internal bool UpdatePersonalInformation(UserUpdatePersonalInformation personalInformation) { var user = Context.Users.Where(c => c.Id == personalInformation.UserId).FirstOrDefault(); var customer = Context.Customers.Where(c => c.Id == user.IdCustomer).FirstOrDefault(); var address = Context.Addresses.Where(c => c.Id == customer.IdAddress).FirstOrDefault(); var oldPhones = Context.PhoneNumbers.Where(c => c.IdCustomer == customer.Id).ToList(); if (user != null && customer != null && address != null && oldPhones != null) { foreach (var phone in oldPhones) { Context.Remove(phone); } customer.Occupation = personalInformation.Occupation; address.IdState = personalInformation.PhysicalAddress.IdState; address.PhysicalAddress = personalInformation.PhysicalAddress.PhysicalAddress; address.ZipCode = personalInformation.PhysicalAddress.ZipCode; address.CityName = personalInformation.PhysicalAddress.CityName; foreach (var newPhoneNumber in personalInformation.PhoneNumbers) { newPhoneNumber.IsActive = true; newPhoneNumber.IdCustomer = customer.Id; Context.Add(newPhoneNumber); } Context.SaveChanges(); return(true); } return(false); }
public ActionResult UpdatePersonalInformation([FromBody] UserUpdatePersonalInformation personalInformation) { if (personalInformation != null) { return(Ok(Service.UpdatePersonalInformation(personalInformation))); } return(BadRequest()); }