private Notification ValidationUpdate(CustomerInputUpdateDto entity) { Notification notification = new Notification(); if (entity == null) { notification.AddError("Invalid JSON data in request body."); return(notification); } if (string.IsNullOrEmpty(entity.FirstName)) { notification.AddError("FirstName is missing"); } else if (entity.FirstName.Length < 2) { notification.AddError("FirstName should have min 2 characters"); } if (string.IsNullOrEmpty(entity.LastName)) { notification.AddError("LastName is missing"); } else if (entity.LastName.Length < 2) { notification.AddError("LastName should have min 2 characters"); } return(notification); }
public int Update(int id, CustomerInputUpdateDto entity) { Notification notification = ValidationUpdate(entity); if (notification.HasErrors()) { throw new ArgumentException(notification.ErrorMessage()); } var customer = _unitOfWork.Customers.Get(id); var identityUser = _unitOfWork.IdentityUsers.Get(customer?.IdentityUserId ?? 0); _customerDomainService.PerformUpdateCustomer(customer, entity.FirstName, entity.LastName, entity.Active, identityUser); _unitOfWork.Customers.Update(customer); _unitOfWork.Complete(); return(customer?.Id ?? 0); }
public IActionResult Put(int id, [FromBody] CustomerInputUpdateDto customer) { _customerApplicationService.Update(id, customer); return(Ok("customer was updated sucessfully")); }