public async Task <ActionResult <dynamic> > EditAddress(VMAddress address) { Address addressToEdit = new Address { AddressId = address.AddressId, Street = address.Street, Number = address.Number, County = address.County, City = address.City, State = address.State, Cep = address.Cep, Complement = address.Complement, }; try { ClientUserAddress clientAddress = _context.ClientUserAddress.Where(t => t.AddressId == address.AddressId).FirstOrDefault(); clientAddress.UpdateDate = DateTime.Now; //throw new Exception(); _context.Address.Update(addressToEdit); _context.ClientUserAddress.Update(clientAddress); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception e) { return(BadRequest(new { Message = "Não foi possivel atualizar o endereço!" })); } }
public async Task <ActionResult <dynamic> > CreateAddress(VMAddress address) { try { var newAddress = new Address() { Cep = address.Cep, Street = address.Street, Number = address.Number, Complement = address.Complement, County = address.County, City = address.City, State = address.State }; _context.Address.Add(newAddress); await _context.SaveChangesAsync(); var clientAddress = new ClientUserAddress() { AddressId = newAddress.AddressId, ClientUserId = address.ClientUserId, InsertDate = DateTime.Now, IsDefault = true, }; _context.ClientUserAddress.Add(clientAddress); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception) { return(BadRequest(new { Message = "Não foi possivel salvar esse endereço" })); } }