Пример #1
0
        public void UpdateIceOption(IceOption iceOption)
        {
            var oIceOption = _appDbContext.IceOptions.FirstOrDefault(io => io.Id == iceOption.Id);

            if (oIceOption == null)
            {
                _appDbContext.IceOptions.Add(iceOption);
            }
            else
            {
                _appDbContext.Entry(oIceOption).State = EntityState.Detached;
                _appDbContext.Entry(iceOption).State  = EntityState.Modified;
                _appDbContext.Update(iceOption);
            };

            if (iceOption.IsPrimary)
            {
                var ices = _appDbContext.IceOptions.Where(s => s.Id != iceOption.Id && s.DrinkId == iceOption.DrinkId);
                foreach (var ice in ices)
                {
                    ice.IsPrimary = false;
                }
            }

            _appDbContext.SaveChanges();
        }
Пример #2
0
        public async Task <IActionResult> UpdateIceOption(IceOption iceOption)
        {
            try
            {
                _drinkRepository.UpdateIceOption(iceOption);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Json(new { success = false }));
            }

            var drink = _drinkRepository.GetDrinkById(iceOption.DrinkId);
            var table = await this.RenderViewAsync("_ListIceOption", drink.IceOptions, true);

            return(Json(new { success = true, html = table }));
        }
Пример #3
0
        public IActionResult UpdateIceOption(int?id, int drinkId)
        {
            var opt = new IceOption();

            if (id == null)
            {
                opt.DrinkId  = drinkId;
                opt.IsActive = true;
            }
            else
            {
                opt = _drinkRepository.GetIceById(id.Value);
                if (opt == null)
                {
                    return(NotFound());
                }
            }

            ViewBag.Units = _drinkRepository.DrinkUnits;
            return(PartialView(opt));
        }