public IHttpActionResult PutCustomer(int id, Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.CustomerID) { return(BadRequest()); } db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <(CustomerProfile, string)> UpdateCustomerProfile(int id, CustomerProfile customer) { string errorMessage = null; try { var custProfile = await _context.CustomerProfile.SingleOrDefaultAsync(c => c.Id == id); if (custProfile != null) { var exisitingCustomer = await _context.CustomerProfile.SingleOrDefaultAsync(c => c.Id != id && c.Email == customer.Email); if (exisitingCustomer != null) { return(null, "Sorry, you cannot use the email address to create account profile."); } custProfile.DOB = customer.DOB; custProfile.FirstName = customer.FirstName; custProfile.Email = customer.Email; custProfile.LastName = customer.LastName; custProfile.MobileNumber = customer.MobileNumber; _context.Entry(custProfile).State = EntityState.Modified; int result = await _context.SaveChangesAsync(); if (result > 0) { return(custProfile, null); } } if (string.IsNullOrEmpty(errorMessage)) { return(null, "Customer profile could not be updated because of some error."); } return(null, errorMessage); } catch (Exception ex) { return(null, "Customer profile could not be updated because of some error."); } }