public ServiceResult Add(Department entity) { var result = _mongoRepository.AddIfNotExist(a => a.Name == entity.Name, entity); return(result ? ServiceResult.IsSuccess(AccountConstString.OperateSuccess) : ServiceResult.IsFailed("已存在相同名称的部门")); }
public void AddIfNotExist_Normal_IsTrue() { var result = MongoRepository.AddIfNotExist("geshiimdb", "UserInfo", new User { Age = 2222, Name = "chengongeee2222" }); Assert.IsTrue(result); }
/// <summary> /// 添加角色 /// </summary> /// <param name="entity"></param> /// <returns></returns> public ServiceResult Add(Role entity) { entity.MenuActionIds = new ObjectId[] { }; entity.MenuId = new ObjectId[] { }; entity.CreateDateTime = DateTime.Now; var result = _mongoRepository.AddIfNotExist(a => a.Name == entity.Name, entity); return(result ? ServiceResult.IsSuccess(AccountConstString.OperateSuccess) : ServiceResult.IsFailed("已存在相同名称的角色")); }
public ServiceResult Add(Administrator administrator) { var userId = ObjectId.GenerateNewId(); administrator.Id = userId; administrator.Password = administrator.Password.EncodePassword(userId.ToString()); administrator.CreateDateTime = DateTime.Now; administrator.UpdateDateTime = DateTime.Now; var result = _mongoRepository.AddIfNotExist(a => a.UserName == administrator.UserName, administrator); return(result ? ServiceResult.IsSuccess(AccountConstString.OperateSuccess) : ServiceResult.IsFailed("已存在该用户名")); }