Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
 public IActionResult AddHouse(House house)
 {
     try
     {
         _houseService.AddHouse(house);
         return(CreatedAtAction("AddHouse", house));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 3
0
 public ActionResult CreateNewHouse(House newHouse)
 {
     _houseService.AddHouse(newHouse);
     return(Ok());
 }