コード例 #1
0
        public bool AddNewPizza(RawNewPizza obj)
        {
            AStore curStore = storeRepo.FindStore(obj.ID);

            if (curStore is null)
            {
                return(false);
            }
            Crust newCrust = storeRepo.GetCrustByID(obj.Crust.ID);

            if (newCrust is null)
            {
                return(false);
            }

            List <Topping> toppings = new List <Topping>();

            foreach (RawComp rc in obj.AllToppings)
            {
                Topping t = storeRepo.GetToppingByID(rc.ID);
                if (t is null)
                {
                    return(false);
                }
                toppings.Add(t);
            }
            BasicPizza newPizza = mapper.RawToBasicPizzaMapper(obj, newCrust, toppings);

            if (!storeRepo.AddPizzaToStore(obj.ID, newPizza))
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Maps a RawPizza from user to BasicPizza
        /// </summary>
        /// <param name="obj">RawPizza from user</param>
        /// <param name="newCrust">Crust obj for BasicPizza</param>
        /// <param name="toppings">List of Topping objects</param>
        /// <returns></returns>
        internal BasicPizza RawToBasicPizzaMapper(RawNewPizza obj, Crust newCrust, List <Topping> toppings)
        {
            BasicPizza newPizza = new BasicPizza();

            newPizza.Type     = obj.Name;
            newPizza.Crust    = newCrust;
            newPizza.Toppings = toppings;
            return(newPizza);
        }
コード例 #3
0
        public void Test_AddNewPizza()
        {
            var options = new DbContextOptionsBuilder <StoreContext>()
                          .UseInMemoryDatabase(databaseName: "TestDb16")
                          .Options;

            using (var context = new StoreContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                StoreRepository storeRepo = new StoreRepository(context);
                StoreLogic      sl        = new StoreLogic(storeRepo);

                AStore store = new AStore();
                store.Name = "Store1";
                ItemType        item        = new ItemType("toppings");
                APizzaComponent testCrust   = new APizzaComponent("testcrust", item);
                APizzaComponent testTopping = new APizzaComponent("testtopping", item);
                Crust           tempCrust   = new Crust(store, 0, 1, testCrust);
                Topping         tempTopping = new Topping(store, 0, 1, testTopping);

                context.Add <AStore>(store);
                context.Add <ItemType>(item);
                context.Add <APizzaComponent>(testCrust);
                context.Add <APizzaComponent>(testTopping);
                context.Add <Crust>(tempCrust);
                context.Add <Topping>(tempTopping);
                context.SaveChanges();

                RawComp rawCrust = new RawComp();
                rawCrust.ID        = tempCrust.CrustID;
                rawCrust.Inventory = 0;
                rawCrust.Name      = "testcrust";
                rawCrust.Price     = 0;

                RawComp rawTopping = new RawComp();
                rawTopping.ID        = tempTopping.ToppingID;
                rawTopping.Inventory = 0;
                rawTopping.Name      = "testtopping";
                rawTopping.Price     = 0;

                RawNewPizza rawTest = new RawNewPizza();
                rawTest.ID          = store.StoreID;
                rawTest.Name        = "testpizza";
                rawTest.Crust       = rawCrust;
                rawTest.AllToppings = new List <RawComp>();
                rawTest.AllToppings.Add(rawTopping);

                Assert.True(sl.AddNewPizza(rawTest));
            }
        }
コード例 #4
0
 public ActionResult <bool> AddNewPizza([FromBody] RawNewPizza obj)
 {
     if (!ModelState.IsValid)
     {
         return(StatusCode(400, "Failed to create models"));
     }
     else
     {
         if (storeLogic.AddNewPizza(obj))
         {
             return(StatusCode(201, "Failed to create models"));
         }
         else
         {
             return(StatusCode(500, "Failed to add pizza"));
         }
     }
 }