public ActionResult ProcessAddUser(UserVM curCreateUserVM) { UserDO submittedUserData = _mappingEngine.Map<UserDO>(curCreateUserVM); string userPassword = curCreateUserVM.NewPassword; bool sendConfirmation = curCreateUserVM.SendMail; string displayMessage; using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { UserDO existingUser = _user.GetExisting(uow, submittedUserData.EmailAddress.Address); if (existingUser != null && String.IsNullOrEmpty(submittedUserData.Id)) { var jsonSuccessResult = Json(_jsonPackager.Pack(new { Data = "User already exists.", UserId = existingUser.Id })); return jsonSuccessResult; } ConvertRoleStringToRoles(curCreateUserVM.Role).Each(e => submittedUserData.Roles.Add(e)); if (existingUser != null) { _user.Update(uow, submittedUserData, existingUser); displayMessage = "User updated successfully."; } else { _user.Create(uow, submittedUserData); displayMessage = "User created successfully."; } if (!String.IsNullOrEmpty(userPassword)) { _user.UpdatePassword(uow, submittedUserData, userPassword); } if (sendConfirmation && !String.IsNullOrEmpty(userPassword)) { _email.SendLoginCredentials(uow, submittedUserData.EmailAddress.Address, userPassword); } } return Json(_jsonPackager.Pack(new { Data = displayMessage })); }
public ActionResult Edit(UserVM usersAdminVM) { using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { var userDO = uow.UserRepository.GetByKey(usersAdminVM.Id); userDO.Id = usersAdminVM.Id; userDO.FirstName = usersAdminVM.FirstName; userDO.LastName = usersAdminVM.LastName; userDO.EmailAddress = new EmailAddressDO { Id = usersAdminVM.EmailAddressID, Address = usersAdminVM.EmailAddress }; userDO.EmailAddressID = usersAdminVM.EmailAddressID; userDO.UserName = usersAdminVM.EmailAddress; // Set RoleId & UserId if role is changed on the font-end other wise IdentityUserRole is set to null and user's role will not be updated. //uow.AspNetUserRolesRepository.AssignRoleIDToUser(usersAdminVM.RoleId, usersAdminVM.Id); uow.SaveChanges(); return RedirectToAction("Index", "User"); } }
public ActionResult RunQuery(UserVM queryParams) { if (string.IsNullOrEmpty(queryParams.EmailAddress) && string.IsNullOrEmpty(queryParams.FirstName) && string.IsNullOrEmpty(queryParams.LastName)) { var jsonErrorResult = Json(_jsonPackager.Pack(new { Error = "Atleast one field is required" })); return jsonErrorResult; } if (queryParams.EmailAddress != null) { var ru = new RegexUtilities(); if (!(ru.IsValidEmailAddress(queryParams.EmailAddress))) { var jsonErrorResult = Json(_jsonPackager.Pack(new { Error = "Please provide valid email address" })); return jsonErrorResult; } } using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { var query = uow.UserRepository.GetQuery(); if (!String.IsNullOrWhiteSpace(queryParams.FirstName)) query = query.Where(u => u.FirstName.Contains(queryParams.FirstName)); if (!String.IsNullOrWhiteSpace(queryParams.LastName)) query = query.Where(u => u.LastName.Contains(queryParams.LastName)); if (!String.IsNullOrWhiteSpace(queryParams.EmailAddress)) query = query.Where(u => u.EmailAddress.Address.Contains(queryParams.EmailAddress)); var matchedUsers = query.ToList(); var jsonResult = Json(_jsonPackager.Pack(matchedUsers)); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; } }