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


C# MongoRepository.SingleOrDefault方法代码示例

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


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

示例1: GetRoom

        /// <summary>
        /// Returns the room based on the name, a new room if it doesn't exist, or null if the password is wrong
        /// </summary>
        /// <param name="roomName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static Room GetRoom(string roomName, string password)
        {
            var mongoRepository = new MongoRepository<Room>(ConnectionString);

            Room room = mongoRepository.SingleOrDefault(r => r.Name == roomName);
            if (room == null)
            {
                room = new Room { Name = roomName, Password = password, DateCreated = DateTime.Now };
            }
            else if (room.Password != password)
            {
                room = null;
            }

            return room;
        }
开发者ID:michaelbreyes,项目名称:Gabby,代码行数:22,代码来源:DatabaseManager.cs

示例2: SetCustomer

        public ActionResult SetCustomer(int id, bool isCustomer)
        {
            var repo = new MongoRepository<Customer>();
            var customer =  repo.SingleOrDefault(x => x.InternalId == id);

            if (customer != null)
            {
                customer.IsCustomer = isCustomer;
                repo.Collection.Save(customer);
            }

            return Json(customer, JsonRequestBehavior.AllowGet);
        }
开发者ID:magnus-ahlberg-stratsys,项目名称:WebApplication1,代码行数:13,代码来源:HomeController.cs

示例3: GetRoomAdmin

        public static Room GetRoomAdmin(string roomName)
        {
            var mongoRepository = new MongoRepository<Room>(ConnectionString);

            Room room = mongoRepository.SingleOrDefault(r => r.Name == roomName);

            return room;
        }
开发者ID:michaelbreyes,项目名称:Gabby,代码行数:8,代码来源:DatabaseManager.cs

示例4: GetStoredUserRoles

        public IList<string> GetStoredUserRoles()
        {
            var repository = new MongoRepository<User>();

            User user = repository.SingleOrDefault(u => u.Pid ==
                CasAuthentication.CurrentPrincipal.Identity.Name);
            if (user != null)
            {
                IEnumerable<string> roles = user.Roles;
                return (IList<string>)roles;
            }
            return EMPTY_LIST;
        }
开发者ID:chrisjsherm,项目名称:FoundationPortal,代码行数:13,代码来源:SwapAdminRoleProvider.cs


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