Example #1
0
        public House InsertHouse(HouseRequest newHouse)
        {
            // try catch?
            // if house has null, db has NON-NULL

            // if EntryEntity.State == "Added"
            // remove id from incoming object?
            // create RequestHouse.cs
            // Add throws error on duplicate id
            House houseToInsert = newHouse.ToHouse();

            //map HouseRequest -> House
            // new House(newHouse.name, newHouse.founder, ne)

            // 🤩
            // create method to HouseRequest (.toHouse())
            // do via binding

            // (ignore for now...)
            // 'automapper' package - create profiles that do this job for me
            try
            {
                var EntryEntity = _potterContext.houses.Add(houseToInsert);
                // ? use int from SaveChanges?
                _potterContext.SaveChanges();
                return(houseToInsert);
            } catch (Exception err)
            {
                throw err;
            }
        }
 public static House ToHouse(this HouseRequest houseRequest)
 {
     return(new House()
     {
         HouseName = houseRequest.HouseName,
         Founder = houseRequest.Founder,
         Animal = houseRequest.Animal
     });
 }