本文整理汇总了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;
}
示例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);
}
示例3: GetRoomAdmin
public static Room GetRoomAdmin(string roomName)
{
var mongoRepository = new MongoRepository<Room>(ConnectionString);
Room room = mongoRepository.SingleOrDefault(r => r.Name == roomName);
return room;
}
示例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;
}