public async Task <int> Post(MenuPrice model)
        {
            var result = 0;

            if (ModelState.IsValid)
            {
                model.Status = 1;
                //check if price for that size is available, even deleted. just update the exist record
                // and change status to using(in case it was delete)
                var checkExist = await _menuPriceBusiness.CheckExistPrice(model);

                if (checkExist != null)
                {
                    model.Id = checkExist.Id;
                    var modelupdate = await _menuPriceBusiness.Update(model);

                    if (checkExist.Status == (int)EStatus.Delete)
                    {
                        await _menuPriceBusiness.SetActive(checkExist.Id, (int)checkExist.Status);
                    }
                    result = checkExist.Id;
                }
                else
                {
                    var modelInsert = await _menuPriceBusiness.Add(model);

                    result = modelInsert.Id;
                }
            }
            return(result);
        }
Пример #2
0
        public async Task <MenuPrice> Add(MenuPrice model)
        {
            var entity = _menuPriceRepository.Add(model);
            await _menuPriceRepository.SaveChangeAsync();

            return(model);
        }
Пример #3
0
        public async Task <MenuPrice> CheckExistPrice(MenuPrice model)
        {
            var record = await _menuPriceRepository.Repo.FirstOrDefaultAsync(c => c.RestaurantId == model.RestaurantId && c.MenuId == model.MenuId &&
                                                                             c.SizeId == model.SizeId);

            return(record);
        }
        public void TestMethodMenuPrice()
        {
            MenuPrice p = new MenuPrice();
            int       totalmenuprice = p.menuPrice(10, 30, 40);

            int expectedMenuprice = 10 + 30 + 40;

            Assert.AreEqual(expectedMenuprice, totalmenuprice);
        }
        public async Task <bool> Put(MenuPrice model)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                result = await _menuPriceBusiness.Update(model);
            }
            return(result);
        }
Пример #6
0
        public void Edit(MenuPrice priceChanges)
        {
            var price = _ctx.MenuPrices.Find(priceChanges.Id);

            if (price == null)
            {
                return;
            }
            price.Name  = priceChanges.Name;
            price.Price = priceChanges.Price;
            price.Note  = priceChanges.Note;
            _ctx.SaveChanges();
        }
Пример #7
0
        public async Task <bool> Update(MenuPrice model)
        {
            var result = false;
            var record = await _menuPriceRepository.Repo.FirstOrDefaultAsync(c => c.Id == model.Id);

            if (record != null)
            {
                record.MenuId = model.MenuId;
                record.SizeId = model.SizeId;
                record.Price  = model.Price;

                await _menuPriceRepository.SaveChangeAsync();

                result = true;
            }
            return(result);
        }
Пример #8
0
 public void Add(MenuPrice price)
 {
     _ctx.MenuPrices.Add(price);
     _ctx.SaveChanges();
 }