public IHttpActionResult MoveTemplate(string hash) { var model = new ReportMoveModel(); model.Address = new Address { AddressLine1 = "Test" }; model.Landlord = new Person() { LastName = "Test" }; return(Ok(model)); }
public async Task <IHttpActionResult> SaveMove([FromBody] ReportMoveModel model) { var userIds = await GetMyUserIdMappings(); var newAddressOccupation = new AddressOccupation { Address = new Address { AddressLine1 = model.Address?.AddressLine1, AddressLine2 = model.Address?.AddressLine2, AddressLine3 = model.Address?.AddressLine3, City = model.Address?.City, State = model.Address?.State, PostCode = model.Address?.PostCode }, OccupiedFrom = model.MoveInDate ?? DateTime.Today, OccupiedTo = model.MoveOutDate, PersonId = userIds.PersonId }; _context.AddressOccupations.Add(newAddressOccupation); await _context.SaveChangesAsync(); if (model.Landlord?.FirstName != null) { Person landLord; var isNewPerson = model.Landlord.Id == 0; if (isNewPerson) { landLord = new Person { Initial = model.Landlord.Initial, FirstName = model.Landlord.FirstName, MiddleName = model.Landlord.MiddleName, LastName = model.Landlord.LastName, PlaceOfBirth = "NA", DateOfBirth = TVS.API.Misc.Constants.SystemMinDate } } ; else { landLord = _context.People.First(p => p.Id == model.Landlord.Id); } landLord.AddressOwnerships.Add(new AddressOwnership { AddressId = newAddressOccupation.AddressId, OwnedFrom = newAddressOccupation.OccupiedFrom, OwnedTo = newAddressOccupation.OccupiedTo }); if (isNewPerson) { _context.People.Add(landLord); } await _context.SaveChangesAsync(); } return(Ok()); }