public async Task<UserValidationResult> CreateUserAsync(User user) { var userDoc = new BsonDocument(); foreach (PropertyInfo prop in typeof(User).GetProperties()) { if (prop.Name != "Id") { if (prop.GetValue(user) != null) { if (prop.Name == "Role") { userDoc.Add(prop.Name.ToLower(), new BsonDouble((int)(prop.GetValue(user) as Role?))); } else { userDoc.Add(prop.Name.ToLower(), new BsonString(prop.GetValue(user) as string)); } } else { userDoc.Add(prop.Name.ToLower(), new BsonString(string.Empty)); } } } await _usersCollection.InsertOneAsync(userDoc).ConfigureAwait(false); //check to see if user was actually inserted var result = await GetUsersAsync(user); return result; }
public async Task<UserValidationResult> GetUsersAsync(User user) { var builder = Builders<BsonDocument>.Filter; var filter = builder.Empty; foreach (PropertyInfo prop in typeof(User).GetProperties()) { if(prop.GetValue(user) != null) filter = filter & builder.Eq(prop.Name.ToLower(), prop.GetValue(user)); } var userBson = await _usersCollection.Find(filter).ToListAsync().ConfigureAwait(false); var result = new UserValidationResult(); result.IsValid = userBson.Count > 0; var userList = new List<User>(); if (result.IsValid) { foreach (var u in userBson) { var newUser = new User(); newUser.Id = Constants.IdRegex.Match(u.Elements.Where(a => a.Name == "_id").ToList()[0].Value.RawValue.ToJson()).Value.Substring(1); newUser.FirstName = u.Elements.Where(a => a.Name == "firstname").ToList()[0].Value.AsString; newUser.LastName = u.Elements.Where(a => a.Name == "lastname").ToList()[0].Value.AsString; newUser.Email = u.Elements.Where(a => a.Name == "email").ToList()[0].Value.AsString; newUser.Company = Constants.IdRegex.Match(u.Elements.Where(a => a.Name == "company").ToList()[0].Value.RawValue.ToJson()).Value.Substring(1); newUser.Username = u.Elements.Where(a => a.Name == "username").ToList()[0].Value.AsString; var rolenumber = (int)u.Elements.Where(a => a.Name == "role").ToList()[0].Value.AsDouble; newUser.Role = (Role)rolenumber; userList.Add(newUser); } } result.Users = userList; return result; }
public User UpdateUser(User user) { var result = _userDao.UpdateUserAsync(user); result.Wait(); user = result.Result; return user; }
public User CreateUser(User user) { user.Company = (HttpContext.Current.Session["currentcompany"] as Company).Id; var result = _userDao.CreateUserAsync(user); result.Wait(); user = result.Result.Users.First(); return user; }
public ActionResult SaveUser(User user) { if (user.Id == null) { _userBizManager.CreateUser(user); } else { _userBizManager.UpdateUser(user); } return RedirectToAction("Users"); }
public bool ValidateUser(User user) { user.Role = null; var result = _userDao.GetUsersAsync(user); result.Wait(); if (result.Result.IsValid) { user = result.Result.Users.First(); HttpContext.Current.Session["role"] = Enum.GetName(typeof (Role), user.Role); HttpContext.Current.Session["currentuser"] = user; var company = new Company() {Id = user.Company}; company = _companyBizManager.GetCompany(company); HttpContext.Current.Session["currentcompany"] = company; } return result.Result.IsValid; }
public Task<User> UpdateUserAsync(User user) { throw new NotImplementedException(); }
public Task<UserValidationResult> GetUsersAsync(User user) { throw new NotImplementedException(); }
public bool GetUser(User user) { throw new NotImplementedException(); }
public Task<bool> DeleteUserAsync(User user) { throw new NotImplementedException(); }
public async Task<bool> DeleteUserAsync(User user) { var filter = Builders<BsonDocument>.Filter.Eq("_id", ObjectId.Parse(user.Id)); await _usersCollection.DeleteOneAsync(filter).ConfigureAwait(false); return true; }
public async Task<User> UpdateUserAsync(User user) { var filter = Builders<BsonDocument>.Filter.Eq("_id", ObjectId.Parse(user.Id)); var update = Builders<BsonDocument>.Update; var updateList = new List<UpdateDefinition<BsonDocument>>(); foreach (PropertyInfo prop in typeof(User).GetProperties()) { if (prop.Name != "Company" && prop.Name != "Id" && !(prop.Name == "Password" && prop.GetValue(user) == null)) { if (prop.GetValue(user) == null) { updateList.Add(update.Set(prop.Name.ToLower(), "")); } else { var value = prop.Name == "Role" ? (double)(prop.GetValue(user) as Role?) : prop.GetValue(user); updateList.Add(update.Set(prop.Name.ToLower(), value)); } } } await _usersCollection.UpdateOneAsync(filter, update.Combine(updateList)).ConfigureAwait(false); return user; }
public void DeleteUser(User user) { _userDao.DeleteUserAsync(user).Wait(); }
public ActionResult User(User user) { if(user == null) user = new User(); return View(user); }
public ActionResult DeleteUser(User user) { _userBizManager.DeleteUser(user); return RedirectToAction("Users"); }
public ActionResult Analyze(User user) { return View(); }