public IHttpActionResult UpdateRegistrationsbyID([FromBody] RegistrationsParametersUpdate usersParametersUpdate) { if (usersParametersUpdate != null && ModelState.IsValid) { RegistrationsDTO registrationsDTO = _registrationsservice.UpdateRegistrationsbyID(usersParametersUpdate, out ReturnValues returnValues); if (!returnValues.Error) { return(Ok(new ResponseSuccess { Success = true, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message, Data = new { Registration = registrationsDTO } })); } return(Ok(new ResponseError { Success = false, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message })); } return(BadRequest(ModelState)); }
public RegistrationsDTO UpdateRegistrationsbyID(RegistrationsParametersUpdate usersParametersUpdate, out ReturnValues returnValues) { Registration registration; RegistrationsDTO registrationsDTO = null; returnValues = new ReturnValues(); int ID = Convert.ToInt32(usersParametersUpdate.ID); try { registration = _unitOfWork.RegistrationRepository.Get(row => row.ID == ID); if (registration == null) { returnValues.SetReturnValues(true, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.NotFound)); return(registrationsDTO); } registration.Name = usersParametersUpdate.Name; registration.Email = usersParametersUpdate.Email; registration.CPFCNPJ = usersParametersUpdate.CPFCNPJ; registration.Phone = usersParametersUpdate.Phone; registration.Password = Utils.Encrypt(usersParametersUpdate.Password); registration.CEP = usersParametersUpdate.CEP; registration.Address = usersParametersUpdate.Address; registration.Number = usersParametersUpdate.Number; registration.DistrictID = usersParametersUpdate.DistrictID; registration.CityID = usersParametersUpdate.CityID; registration.StateID = usersParametersUpdate.StateID; registration.UpdatedOn = DateTime.Now; _unitOfWork.RegistrationRepository.Update(registration); _unitOfWork.PersistChanges(); registrationsDTO = new RegistrationsDTO { ID = registration.ID.ToString(), Status = registration.Status.ToString(), Name = registration.Name, Email = registration.Email, CPFCNPJ = registration.CPFCNPJ, Phone = registration.Phone, Username = registration.Username, Password = registration.Password, CEP = registration.CEP, Address = registration.Address, Number = registration.Number, DistrictID = registration.DistrictID, CityID = registration.CityID, StateID = registration.StateID, Type = registration.Type, CreatedOn = registration.CreatedOn.ToString(), UpdatedOn = registration.UpdatedOn.ToString() }; returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok)); } catch (Exception ex) { returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message); } return(registrationsDTO); }