当前位置: 首页>>代码示例>>C#>>正文


C# Repository.FindAll方法代码示例

本文整理汇总了C#中Repository.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.FindAll方法的具体用法?C# Repository.FindAll怎么用?C# Repository.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Repository的用法示例。


在下文中一共展示了Repository.FindAll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: About

        public ActionResult About()
        {
            // Generiskt Repository - Här skapas ett repository för Category
            // Repositoryt kräver typer som implementerar IEntity
            Repository<Category> categoryRepo = new Repository<Category>();

            // Samtliga metoder som finns med i det generiska repositoriet
            var categories = categoryRepo.FindAll();

            var filteredCategories = categoryRepo.FindAll(c => c.Name.Contains("sport"));

            var category = categoryRepo.FindByID(0);

            category.Name = "New Name!";
            categoryRepo.Save(category);

            categoryRepo.Delete(category);

            ProductRepository productRepo = new ProductRepository();

            var products = productRepo.FindAll(); // + övriga "grund"-metoder

            // Metoder implementerade i ProductRepository:
            var productsForCategory = productRepo.FindProductsByCategoryID(0);

            var productsWithEmptyName = productRepo.FindAll(ProductRepository
                                                            .FilterProductsWithEmptyDescription);

            return View();
        }
开发者ID:awt2gbg2012,项目名称:Lektion13,代码行数:30,代码来源:HomeController.cs

示例2: Index

        //
        // GET: /Product/
        public ActionResult Index()
        {
            // 2 st. Category plockas fram/skapas och används i demo-syfte.
            // Vi kan tänka oss att vi fått dessa som resultat av User Input
            var categoryRepo = new Repository<Category>();
            Category oldCategory = categoryRepo
                                    .FindAll(c => c.Name.Contains("New"))
                                    .OrderByDescending(c => c.ID)
                                    .FirstOrDefault();
            if (null == oldCategory) oldCategory = categoryRepo.FindAll().FirstOrDefault();

            var newCategory = new Category
            {
                Name = string.Format("NewCategory - {0}",
                                     DateTime.UtcNow.ToShortDateString())
            };

            // Nedanstående vill vi inte ha i ProductController - Dags att bryta ut
            //
            // I det här fallet så uppdaterar vi Category för alla produkter med oldCategory till newCategory.
            // Vi skulle kunna tänka oss en större operation här - men detta duger i övningssyfte.
            //
            // Poängen är att detta är logik som inte direkt rör user input/output.
            // Dvs: det bör inte ligga i Controller utan någonstanns i .Domain-projektet.
            var filteredProducts = _productRepo
                                    .FindAll(p => p.CategoryID == oldCategory.ID)
                                    .ToList();
            foreach (var productToUpdate in filteredProducts)
            {
                productToUpdate.Category = newCategory;
                _productRepo.Save(productToUpdate);
            }

            return View();
        }
开发者ID:awt2gbg2012,项目名称:Lektion13,代码行数:37,代码来源:ProductController.cs

示例3: GetProductList

 private static async Task<IList<Product>> GetProductList()
 {
     var repo = new Repository<Product>("products");
     var list = await repo.FindAll();
     return list.OrderBy(x => x.ProductName)
         .ToList();
 }
开发者ID:farihan,项目名称:MongoDBCRUD,代码行数:7,代码来源:Program.cs

示例4: GetMosqueList

 private static async Task<IList<Mosque>> GetMosqueList()
 {
     var repo = new Repository<Mosque>("mosques");
     var list = await repo.FindAll();
     return list.OrderBy(x => x.Name)
         .ToList();
 }
开发者ID:farihan,项目名称:MongoDBCRUD,代码行数:7,代码来源:Program.cs

示例5: IsAuthorizedCompany

 public static bool IsAuthorizedCompany(HttpContextBase context/*, Guid EventID*/)
 {
     var userRepo = new Repository<User>();
     var user = userRepo.FindAll(u => u.UserName.ToLower() == context.User.Identity.Name.ToLower()).FirstOrDefault();
     //var EventOwnerID = user.UserName;
     if (user == null)
         return false;
     else
         return true;
         //user == null ? false : user.ID == EventID;
 }
开发者ID:NiklasAndren,项目名称:Missionny,代码行数:11,代码来源:AuthorizeAdminAttribute.cs

示例6: GetAll

        public IList<UserDto> GetAll()
        {
            IList<UserDto> userDtos = null;

            using (ISession session = _sessionFactory.OpenSession())
            {
                IRepository<User> userRepository = new Repository<User>(session);
                var users = userRepository.FindAll().List();
                userDtos = Mapper.Map<IList<UserDto>>(users);
            }

            return userDtos;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:13,代码来源:UserStorageProxy.cs

示例7: GetAll

        public IList<GroupDto> GetAll()
        {
            IList<GroupDto> groupDtos = null;

            using (ISession session = _sessionFactory.OpenSession())
            {
                IRepository<Group> groupRepository = new Repository<Group>(session);
                var groups = groupRepository.FindAll().List();
                groupDtos = Mapper.Map<IList<GroupDto>>(groups);
            }

            return groupDtos;
        }
开发者ID:SadiqAhmed,项目名称:MyNotes,代码行数:13,代码来源:GroupStorageProxy.cs

示例8: Delete

        public string Delete(string argument)
        {
            AjaxResult ajaxResult = new AjaxResult();

            string errorMsg = string.Empty;
            DoResult doResult = DoResult.Failed;
            string actionMessage = string.Empty;
            try
            {
                if (!string.IsNullOrWhiteSpace(argument))
                {
                    string roleID = argument;

                    IRepository<string> repository = new Repository<string>();
                    IDictionary<string, object> parameters = new Dictionary<string, object>();
                    parameters.SafeAdd("RoleID", roleID);
                    IList<ObjectRole> objectRoleList = repository.FindAll<ObjectRole>(parameters);
                    if (objectRoleList.Count == 0)
                    {
                        repository.Delete<Role>(roleID);
                        repository.ExecuteSql<RolePrivilege>(string.Format("Delete from AC_RolePrivilege where RoleID='{0}'", roleID));
                        doResult = DoResult.Success;
                        actionMessage = RemarkAttribute.GetEnumRemark(doResult);
                    }
                    else
                    {
                        doResult = DoResult.Failed;
                        actionMessage = "请先解除该角色与操作员的关联!";
                    }

                    ajaxResult.RetValue = CurrentId;
                    ajaxResult.PromptMsg = actionMessage;
                }

                ajaxResult.Result = doResult;
            }
            catch (Exception ex)
            {
                actionMessage = RemarkAttribute.GetEnumRemark(doResult);
                log.Error(actionMessage, ex);
            }

            return JsonConvert.SerializeObject(ajaxResult);
        }
开发者ID:AgileEAP,项目名称:WebStack,代码行数:44,代码来源:RoleManager.aspx.cs

示例9: ConfirmAccount

        public bool ConfirmAccount(string Id)
        {
            var userRepo = new Repository<User>();
            var currentUser = userRepo.FindAll(u => u.ConfirmationToken == Id).FirstOrDefault();

            if (currentUser != null)
            {
                currentUser.IsConfirmed = true;
                userRepo.Update(currentUser);
                return true;
            }
            return false;
        }
开发者ID:RobPas,项目名称:MiniFB,代码行数:13,代码来源:CustomMembershipProvider.cs

示例10: CreateConfirmationToken

        public string CreateConfirmationToken(string UserName)
        {
            var userRepo = new Repository<User>();
            var currentUser = userRepo.FindAll(u => u.UserName == UserName).FirstOrDefault();

            currentUser.ConfirmationToken = Guid.NewGuid().ToString();
            userRepo.Update(currentUser);

            return currentUser.ConfirmationToken;
        }
开发者ID:RobPas,项目名称:MiniFB,代码行数:10,代码来源:CustomMembershipProvider.cs


注:本文中的Repository.FindAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。