Exemplo n.º 1
0
        public ComponentStocks ConfirmOrder(ComponentUpdate componentUpdate)
        {
            ComponentHelper componentHelper = new ComponentHelper();

            using (var ctx = new CoffeShopContext())
            {
                List <Component> componentList = ctx.Components.ToList();
                var componentStocks            = componentHelper.CalculateNewStocks(componentUpdate, componentList);

                for (int i = 0; i < componentList.Count; i++)
                {
                    if (componentList[i].ComponentName == "Milk")
                    {
                        componentList[i].Stock = componentStocks.MilkInStock;
                    }
                    else if (componentList[i].ComponentName == "Coffe")
                    {
                        componentList[i].Stock = componentStocks.CoffeInStock;
                    }
                    else if (componentList[i].ComponentName == "Water")
                    {
                        componentList[i].Stock = componentStocks.WaterInStock;
                    }
                }

                ctx.SaveChanges();
                return(componentStocks);
            }
        }
Exemplo n.º 2
0
 public List <Component> GetStockData()
 {
     using (var ctx = new CoffeShopContext())
     {
         List <Component> componentList = ctx.Components.ToList();
         return(componentList);
     }
 }
Exemplo n.º 3
0
 public List <Coffe> GetCoffes()
 {
     using (var ctx = new CoffeShopContext())
     {
         List <Coffe> coffeList = ctx.Coffes.ToList();
         return(coffeList);
     }
 }
Exemplo n.º 4
0
 public UserController(IRepository <Role, CoffeShopContext> roleRepository, IRepository <User, CoffeShopContext> userRepository, IRepository <Models.CoffeShop, CoffeShopContext> coffeShopRepository, IRepository <ItemComponent, CoffeShopContext> itemComponentRepository, IRepository <Component, CoffeShopContext> componentRepository, CoffeShopContext context, IRepository <ItemGroup, CoffeShopContext> itemGroupRepository, IRepository <Item, CoffeShopContext> itemRepository)
 {
     _roleRepository          = roleRepository;
     _userRepository          = userRepository;
     _coffeShopRepository     = coffeShopRepository;
     _itemComponentRepository = itemComponentRepository;
     _itemGroupRepository     = itemGroupRepository;
     _componentRepository     = componentRepository;
     _context        = context;
     _itemRepository = itemRepository;
 }
Exemplo n.º 5
0
 public List <Coffe_CoffeSize_View> GetCoffeSizeByCoffeId(int coffeId)
 {
     using (var ctx = new CoffeShopContext())
     {
         List <Coffe_CoffeSize_View> coffeList = (from cmapping in ctx.CoffeSize_Mappings
                                                  join coffe in ctx.Coffes on cmapping.CoffeId equals coffe.Id
                                                  join coffeSize in ctx.CoffeSizes on cmapping.CoffeSizeId equals coffeSize.Id
                                                  where cmapping.CoffeId == coffeId
                                                  select new Coffe_CoffeSize_View()
         {
             CoffeId = coffe.Id,
             Id = cmapping.Id,
             CoffeSizeId = coffeSize.Id,
             MilkNeed = (decimal)cmapping.MilkNeed,
             CoffeNeed = (decimal)cmapping.CoffeNeed,
             WaterNeed = (decimal)cmapping.WaterNeed,
             Size = coffeSize.Size
         }).ToList();
         return(coffeList);
     }
 }
Exemplo n.º 6
0
        public ResponseBase GetOffer(decimal milkneed, decimal coffeneed, decimal waterneed, bool milkCheck, bool coffeCheck, bool waterCheck)
        {
            ComponentHelper componentHelper = new ComponentHelper();

            using (var ctx = new CoffeShopContext())
            {
                List <Component> componentList = ctx.Components.ToList();
                var checkStocksAreValid        = componentHelper.CheckStocksAreValid(milkneed, coffeneed, waterneed, componentList, milkCheck, coffeCheck, waterCheck);
                if (checkStocksAreValid.IsOk)
                {
                    decimal price = componentHelper.CalculatePrice(milkneed, coffeneed, waterneed, componentList);

                    if (milkCheck)
                    {
                        decimal milkPrice = componentList.Where(x => x.ComponentName == "Milk").Select(x => x.UnitPrice).FirstOrDefault();
                        price = componentHelper.AddExtraUnitPricePriceToPrice(price, milkPrice);
                    }

                    if (coffeCheck)
                    {
                        decimal coffePrice = componentList.Where(x => x.ComponentName == "Coffe").Select(x => x.UnitPrice).FirstOrDefault();
                        price = componentHelper.AddExtraUnitPricePriceToPrice(price, coffePrice);
                    }

                    if (waterCheck)
                    {
                        decimal waterPrice = componentList.Where(x => x.ComponentName == "Water").Select(x => x.UnitPrice).FirstOrDefault();
                        price = componentHelper.AddExtraUnitPricePriceToPrice(price, waterPrice);
                    }

                    return(new ResponseBase {
                        ExtraData = price.ToString("#.##"), IsOk = true
                    });
                }

                return(checkStocksAreValid);
            }
        }
 public ComponentLeavingsViewComponent(CoffeShopContext context, IRepository <ComponentDelivery, CoffeShopContext> componentDeliveryRepository, IRepository <Component, CoffeShopContext> componentRepository)
 {
     _context = context;
     _componentDeliveryRepository = componentDeliveryRepository;
     _componentRepository         = componentRepository;
 }
Exemplo n.º 8
0
 public AccountController(CoffeShopContext context, IRepository <Role, CoffeShopContext> roleRepository, IRepository <User, CoffeShopContext> userRepository)
 {
     _roleRepository = roleRepository;
     _userRepository = userRepository;
     _context        = context;
 }
Exemplo n.º 9
0
 public RaportController(CoffeShopContext context, IRepository <ComponentDelivery, CoffeShopContext> componentDeliveryRepository, IRepository <Component, CoffeShopContext> componentRepository)
 {
     _context = context;
     _componentDeliveryRepository = componentDeliveryRepository;
     _componentRepository         = componentRepository;
 }
 public ItemLeavingsViewComponent(IRepository <Item, CoffeShopContext> itemRepository, CoffeShopContext context, IRepository <ItemComponent, CoffeShopContext> itemComponentRepository)
 {
     _itemRepository          = itemRepository;
     _itemComponentRepository = itemComponentRepository;
     _context = context;
 }
Exemplo n.º 11
0
 public HomeController(CoffeShopContext context)
 {
     _context = context;
 }