public async Task <ActionResult <AdminDto> > UpdateAdmin(Guid adminId, AdminUpdateDto adminUpdateDto) { if (!await _adminRepository.AdminExistAsync(adminId)) { return(NotFound()); } var admin = await _adminRepository.GetAdminAsync(adminId); if (admin == null) { var adminToAdd = _mapper.Map <Admin>(adminUpdateDto); adminToAdd.AdminId = adminId; _adminRepository.AddAdmin(adminToAdd); await _adminRepository.SaveAsync(); var adminDtoNew = _mapper.Map <AdminDto>(adminToAdd); return(CreatedAtRoute(nameof(GetAdmin), new { adminId = admin.AdminId }, adminDtoNew)); } _mapper.Map(adminUpdateDto, admin); _adminRepository.UpdateAdmin(admin); await _adminRepository.SaveAsync(); var adminDto = _mapper.Map <AdminDto>(admin); return(CreatedAtRoute(nameof(GetAdmin), new { adminId = admin.AdminId }, adminDto)); }
/// <summary> /// Update admin /// </summary> /// <param name="adminUpdate"></param> /// <returns></returns> public async Task <AdminDto> UpdateAdmin(AdminUpdateDto adminUpdate) { AdminUser user = db.AdminsRepository.Get(a => a.Id == adminUpdate.Id).FirstOrDefault(); if (user == null) { // 404, Not found. // No reason for an exception I think return(null); } AdminsConverter.UpdateAdminsPersonalData(user, adminUpdate); var result = await db.AuthRepository.UpdateUser(user); if (!result.Succeeded) { var ex = new UserUpdateException(result.Errors.ToArray()); ex.Data.Add("IdentityResultErrors", result.Errors.ToArray()); throw ex; } var updatedUser = db.AdminsRepository.Get(a => a.Id == adminUpdate.Id).FirstOrDefault(); return(AdminsConverter.AdminToAdminDto(updatedUser)); }
public ActionResult UpdateAdmin(int id, [FromBody] AdminUpdateDto adminUpdateDto) { var isUpdated = this._adminService.UpdateAdmin(id, adminUpdateDto); if (!isUpdated) { return(this.BadRequest()); } return(this.NoContent()); }
public async Task <IDataResult <AdminDto> > Update(AdminUpdateDto adminUpdateDto) { if (adminUpdateDto != null) { var admin = _mapper.Map <Admin>(adminUpdateDto); await _unitOfWork.Admin.UpdateAsync(admin); await _unitOfWork.SaveAsync(); return(new DataResult <AdminDto>(ResultStatus.Success, new AdminDto { Admin = admin })); } return(new DataResult <AdminDto>(ResultStatus.Error, "Hata. Girdiğiniz bilgileri kontrol ediniz.", null)); }
public bool UpdateAdmin(int id, AdminUpdateDto adminUpdateDto) { Admin existingAdmin = this._repository.GetById(id); if (existingAdmin == null) { return(false); } this._mapper.Map(adminUpdateDto, existingAdmin); this._repository.Update(existingAdmin); this._repository.SaveChanges(); return(true); }
public async Task <IDataResult <AdminDto> > Update(AdminUpdateDto adminUpdateDto, string modifiedByName) { var admin = _mapper.Map <Admin>(adminUpdateDto); admin.ModifiedByName = modifiedByName; var updatedAdmin = await _unitOfWork.Admin.UpdateAsync(admin); await _unitOfWork.SaveAsync(); return(new DataResult <AdminDto>(ResultStatus.Success, new AdminDto { Admin = admin, ResultStatus = ResultStatus.Success, Message = "İşlem başarılı." })); }
public async Task <IHttpActionResult> UpdateAdmin([FromUri] int adminId, [FromBody] AdminUpdateDto adminUpdate) { var userData = IdentityHelper.GetLoggedInUser(RequestContext); logger.Info("Update Admin {@adminReg} by {@userData}", adminUpdate, userData); if (adminId != adminUpdate.Id) { logger.Info("Provided Ids do not match"); return(BadRequest("Ids do not match")); } AdminDto updatedAdmin = await service.UpdateAdmin(adminUpdate); if (updatedAdmin == null) { return(NotFound()); } return(Ok(updatedAdmin)); }
public async Task <IActionResult> EditAdmin(AdminUpdateDto adminUpdateDto, string oldPsswrd, string oldSQHash) { if (ModelState.IsValid) { if (oldPsswrd != adminUpdateDto.PasswordHash) { using var md5 = MD5.Create(); var result1 = md5.ComputeHash(Encoding.ASCII.GetBytes(adminUpdateDto.PasswordHash)); var strResult = BitConverter.ToString(result1); adminUpdateDto.PasswordHash = strResult.Replace("-", ""); } if (oldSQHash != adminUpdateDto.SQAnswerHash) { using var md5New = MD5.Create(); var result2 = md5New.ComputeHash(Encoding.ASCII.GetBytes(adminUpdateDto.SQAnswerHash)); var strResult2 = BitConverter.ToString(result2); adminUpdateDto.SQAnswerHash = strResult2.Replace("-", ""); } await _adminService.Update(adminUpdateDto, "Hasan Erdal"); return(RedirectToAction("Setting")); } return(View(adminUpdateDto)); }