public async Task <IActionResult> CreateHouse([FromBody] HouseBindingModel model) { if (ModelState.IsValid) { try { var houseMate = _houseMateService.GetHouseMate(model.CreatorId); if (houseMate.HouseId != 0) { throw new Exception("houseMate already is a member of a house"); } //first add house to db House house = new House(); ParseHouseFields(house, model); //TODO: I dont need to return thisI don't think... somehow EF/.NET brings the new guy along... House houseAdded = _houseService.AddHouse(house); //Add houseId to houseMate and save in database houseMate.HouseId = houseAdded.Id; await _houseMateService.UpdateHouseMate(houseMate); return(Ok(houseAdded)); } catch (Exception) { throw new Exception("there was an error adding the house"); } } return(BadRequest("Shitty request")); }
private void ParseHouseFields(House house, HouseBindingModel model) { house.Name = model.Name; house.Address1 = model.Address1; house.Address2 = model.Address2; house.City = model.City; house.Zip = model.Zip; house.State = model.State; house.CreatorId = model.CreatorId; }