public SaveResult <UserEntryModel> Save(UpdatePasswordDTO updatePasswordDTO, DateTime dateStamp) { var passwordHasher = new MD5PasswordHasher(); var user = Db.tblM_User.Find(User.User_PK); ModelValidationResult validationResult = validator.Validate(updatePasswordDTO); bool success = false; UserEntryModel model = null; if (validationResult.IsValid) { var hashedCurrentPassword = passwordHasher.Hash(updatePasswordDTO.CurrentPassword); if (hashedCurrentPassword != user.Password) { throw new Kairos.KairosException("Wrong current password."); } var hashedNewPassword = passwordHasher.Hash(updatePasswordDTO.NewPassword); user.Password = hashedNewPassword; Db.SaveChanges(); } return(new SaveResult <UserEntryModel> { Success = success, Message = validationResult.IsValid ? "Password has been changed." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
public SaveResult <UserEntryModel> Save(UserDTO userDTO, DateTime dateStamp) { ModelValidationResult validationResult = userValidator.Validate(userDTO); bool success = false; UserEntryModel model = null; if (validationResult.IsValid) { UserDetailCreateHandler userDetailCreateHandler = new UserDetailCreateHandler(Db, User, new UserDetailValidator(), new UserDetailFactory(Db, User), new UserDetailQuery(), accessControl); var userDetailSaveResult = userDetailCreateHandler.Save(userDTO, dateStamp); if (userDetailSaveResult.Success) { userDTO.UserDetail_FK = userDetailSaveResult.Model.Model.UserDetail_PK; tblM_User user = Insert(userDTO, dateStamp); Db.SaveChanges(); success = true; model = userEntryDataProvider.Get(user.User_PK); } } return(new SaveResult <UserEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
public IHttpActionResult PostStudent(UserEntryModel userModel) { var newStudent = new User(); _studentsServices.Map(newStudent, userModel); _studentsServices.Add(newStudent); var stringparameter = _encryption.Encrypt(newStudent.AccountId); _email.Send(newStudent.Email, "Hacer click en el siguiente link para activar su cuenta: " + HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/api/Students/" + HttpContext.Current.Server.UrlEncode(stringparameter) + "/Active", "Vinculación"); return(Ok(newStudent)); }
public void Map(User student, UserEntryModel userModel) { student.AccountId = userModel.AccountId; student.Name = userModel.Name; student.Password = _encryption.Encrypt(userModel.Password); student.Major = _majorServices.Find(userModel.MajorId); student.Campus = userModel.Campus; student.Email = userModel.Email; student.Status = Status.Inactive; student.CreationDate = DateTime.Now; student.ModificationDate = DateTime.Now; student.Finiquiteado = false; }
public IHttpActionResult PostStudent(UserEntryModel userModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newUser = StudentsServices.Map(userModel); StudentsServices.Add(newUser); var stringparameter = EncryptDecrypt.Encrypt(newUser.AccountId); MailManager.SendSimpleMessage(newUser.Email, "Hacer click en el siguiente link para Activar: " + HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/api/Students/" + HttpContext.Current.Server.UrlEncode(stringparameter) + "/Active", "Vinculación"); return(Ok(newUser)); }
public User Map(UserEntryModel userModel) { var newUser = new User(); newUser.AccountId = userModel.AccountId; newUser.Name = userModel.Name; newUser.Password = EncryptDecrypt.Encrypt(userModel.Password); newUser.Major = _majorRepository.GetMajorByMajorId(userModel.MajorId);; newUser.Campus = userModel.Campus; newUser.Email = userModel.Email; newUser.Status = Status.Inactive; newUser.CreationDate = DateTime.Now; newUser.ModificationDate = DateTime.Now; return(newUser); }
public IHttpActionResult PostStudent(UserEntryModel userModel) { var newStudent = new User(); _studentsServices.Map(newStudent, userModel); _studentsServices.Add(newStudent); var stringparameter = HexadecimalEncoding.ToHexString(newStudent.AccountId); _email.Send(newStudent.Email, "Hacer click en el siguiente link para activar su cuenta: " + backEndSite + "/api/Students/" + HttpContext.Current.Server.UrlEncode(stringparameter) + "/Active", "Vinculación"); return(Ok(newStudent)); }
public SaveResult <UserEntryModel> Save(UserDTO userDTO, DateTime dateStamp) { if (userDTO.Status_FK == 0) { userDTO.Status_FK = 1; } ModelValidationResult validationResult = userValidator.Validate(userDTO); bool success = false; UserEntryModel model = null; if (validationResult.IsValid) { userDTO.Username = userDTO.UserCode = new UserCodeGenerator(this.Db).GetNextUserCode(); UserDetailCreateHandler userDetailCreateHandler = new UserDetailCreateHandler(Db, User, new UserDetailValidator(), new UserDetailFactory(Db, User), new UserDetailQuery(), accessControl); var userDetailSaveResult = userDetailCreateHandler.Save(userDTO, dateStamp); if (userDetailSaveResult.Success) { userDTO.UserDetail_FK = userDetailSaveResult.Model.Model.UserDetail_PK; tblM_User user = Insert(userDTO, dateStamp); Db.SaveChanges(); userDTO.User_PK = user.User_PK; CreateRoleGroupIfJabatanIsAssignable(userDTO, dateStamp); success = true; model = userEntryDataProvider.Get(user.User_PK); } } return(new SaveResult <UserEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
public SaveResult <UserEntryModel> Save(UserDTO userDTO, DateTime dateStamp) { userDTO.Username = userDTO.UserCode; var user = Db.tblM_User.Find(userDTO.User_PK); userDTO.Password = user.Password; ModelValidationResult validationResult = userValidator.Validate(userDTO); bool success = false; UserEntryModel model = null; if (validationResult.IsValid) { UserDetailUpdateHandler userDetailCreateHandler = new UserDetailUpdateHandler(Db, User, new UserDetailValidator(), new UserDetailFactory(Db, User), new UserDetailQuery(), accessControl); var userDetailSaveResult = userDetailCreateHandler.Save(userDTO, dateStamp); if (userDetailSaveResult.Success) { success = true; DeleteMappingUserRoleGroup(userDTO); UpdateUser(userDTO, dateStamp); Db.SaveChanges(); CreateRoleGroupIfJabatanIsAssignable(userDTO, dateStamp); model = userEntryDataProvider.Get(userDTO.User_PK); } } return(new SaveResult <UserEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }