Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Order,CategoryId,BrandId,ImageUrl,Price,ProductionDate,Manufacturer,Name,Id")] Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]    = new SelectList(_context.Brands, "Id", "Id", product.BrandId);
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId);
            return(View(product));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Создать или обновить данные в базе
        /// </summary>
        /// <param name="goodDtos">Товары полученные из файлов</param>
        public void CreateOrUpdate(List <GoodDto> goodDtos)
        {
            var list = goodDtos.GroupBy(e => new
            {
                e.OrderNum,
                e.Material,
                e.Size
            });

            foreach (var item in list)
            {
                var goods = _context.Goods.AsNoTracking()
                            .Where(e => e.OrderNum == item.Key.OrderNum && e.Material == item.Key.Material && e.Size == item.Key.Size)
                            .ToList();

                var sessionRows = item.Select(e => e.OnOrdQty + e.ShipQty).Sum();
                var good        = item.FirstOrDefault();

                if (!goods.Any())
                {
                    CreateGood(good, sessionRows, goods.Count);
                }
                else
                {
                    //step by update
                    bool hasDifferent = goods.Any(e =>
                                                  !e.OrderType.Equals(good.OrderType) ||
                                                  !e.SoldTo.Equals(good.SoldTo) ||
                                                  !e.CustName.Equals(good.CustName));

                    if (hasDifferent)
                    {
                        foreach (var existGood in goods)
                        {
                            good.Id = existGood.Id;
                            _context.Update(_mapper.Mapper.Map(good, existGood));
                        }
                    }

                    //step by new create
                    if (sessionRows > goods.Count)
                    {
                        good.Id = Guid.Empty;
                        CreateGood(good, sessionRows, goods.Count);
                    }
                }
                _context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 public async Task EditAsync(Location location)
 {
     _db.Update(location);
     await _db.SaveChangesAsync();
 }
Ejemplo n.º 4
0
 public async Task EditAsync(Floor floor)
 {
     _db.Update(floor);
     await _db.SaveChangesAsync();
 }
Ejemplo n.º 5
0
 public void Update(T entity)
 {
     _context.Update(entity);
 }