private UserModel PrepareUserModel(User user) { Guard.IsNotNull(user, "user"); var model = new UserModel() { RowId = user.RowId, Username = user.Username, FirstName = encryptionService.AESDecrypt( user.GetAttribute<string>(SystemUserAttributeNames.FirstName), user), LastName = encryptionService.AESDecrypt( user.GetAttribute<string>(SystemUserAttributeNames.LastName), user), UserRoleNames = user.UserRoles.Select(ur => ur.Name).ToDelimitedString(", "), CreatedOn = user.CreatedOn.ToString(StateKeyManager.DateFormat), LastActivityDate = user.LastActivityDate.HasValue ? user.LastActivityDate.Value.ToString(StateKeyManager.DateTimeFormat) : string.Empty }; PrepareOfficeAssociationModel(model, user, officeService, cacheManager); PrepareAuditHistoryModel(model, user); return model; }
public ActionResult Create(UserModel model) { if (ModelState.IsValid) { var request = new UserRegistrationRequest( model.Username, encryptionService.GetSHAHash(StateKeyManager.TemporaryPassword, true), PublishingStatus.PendingApproval); // set the other properties request.FirstName = model.FirstName; request.LastName = model.LastName; request.Mobile = model.Mobile; request.IsAdministrator = model.IsAdministrator; // register this user var result = registrationService.RegisterUser(request); if (result.Success) { // add the associated branches to this user var associatedOffices = model.OfficeId.ToList<Guid>(); attributeService.SaveAttribute<List<Guid>>(result.Data, SystemAttributeNames.AssociatedBrancOffices, associatedOffices); result.Data.AuditHistory.Add ( userActivityService.InsertActivity(SystemActivityLogTypeNames.EntityOfficeAssociation, PrepareOfficeAssociationModel(associatedOffices,officeService,cacheManager), StateKeyManager.USER_ACTIVITY_COMMENT, request.Username) ); userService.Update(result.Data); // send the user activation email messageService.SendUserEmailValidationMessage(result.Data, workContext.WorkingLanguage.RowId); // return notification message SuccessNotification(localizationService.GetResource("Users.Added")); return RedirectToAction(SystemRouteNames.Index); } } //If we got this far, something failed, redisplay form model.AvailableOffices = base.PrepareSelectList(officeService, cacheManager); return View(model); }
public ActionResult Edit(UserModel model) { if (ModelState.IsValid) { var request = new UserRegistrationRequest( model.Username, string.Empty); // set the other properties request.FirstName = model.FirstName; request.LastName = model.LastName; request.Mobile = model.Mobile; request.IsAdministrator = model.IsAdministrator; // register this user var result = registrationService.UpdateRegistration(request); if (result.Success) { // add the associated branches to this user var associatedOffices = model.OfficeId.ToList<Guid>(); attributeService.SaveAttribute<List<Guid>>(result.Data, SystemAttributeNames.AssociatedBrancOffices, associatedOffices); result.Data.AuditHistory.Add ( userActivityService.InsertActivity(SystemActivityLogTypeNames.EntityOfficeAssociation, PrepareOfficeAssociationModel(associatedOffices, officeService, cacheManager), StateKeyManager.USER_ACTIVITY_COMMENT, request.Username) ); userService.Update(result.Data); // return notification message SuccessNotification(localizationService.GetResource("Users.Updated")); return RedirectToAction(SystemRouteNames.Index); } } //If we got this far, something failed, redisplay form model.AvailableOffices = base.PrepareSelectList(officeService, cacheManager); var user = userService.GetById(model.RowId); if (user == null) return RedirectToAction(SystemRouteNames.Index); model.Mobile = encryptionService.AESDecrypt(user.GetAttribute<string>(SystemUserAttributeNames.Mobile), user); model.IsAdministrator = user.IsInUserRole(SystemUserRoleNames.Administrators); return View(model); }
public ActionResult Create() { var model = new UserModel(); model.AvailableOffices = base.PrepareSelectList(officeService, cacheManager); return View(model); }