public async Task UpsertAsync(ProductionAreas productionAreas)
        {
            if (_context.ProductionAreas.AsNoTracking().Any(x => x.Id == productionAreas.Id))
            {
                _context.Attach(productionAreas);
                _context.Update(productionAreas);
            }
            else
            {
                await _context.AddAsync(productionAreas);
            }

            await _context.SaveChangesAsync();
        }
        public async Task UpsertAsync(Product product)
        {
            if (_context.Products.AsNoTracking().Any(x => x.Id == product.Id))
            {
                _context.Attach(product);
                _context.Update(product);
                //_context.Entry(product).State = EntityState.Modified;
            }
            else
            {
                await _context.AddAsync(product);
            }

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public void PutOrder(int id, [FromBody] string value)
        {
            Order order = _context.Orders.FirstOrDefault(o => o.OrderId == id);

            if (order != null)
            {
                order.Shipped = true;
                //_context.SaveOrder(order);

                var marketingEventList = order.Lines.Where(m => m.MarketingEvent != null).Select(l => l.MarketingEvent);

                List <int> newList = new List <int>();
                foreach (var item in marketingEventList)
                {
                    if (newList.IndexOf(item.MarketingEventId) == -1)
                    {
                        newList.Add(item.MarketingEventId);
                        _context.Attach(item);
                    }
                }

                _context.AttachRange(order.Lines.Select(l => l.Product));
                _context.AttachRange(order.Customer);
                _context.AttachRange(order.Outlet);
                _context.AttachRange(order.Warehouse);
                if (order.OrderId == 0)
                {
                    _context.Orders.Add(order);
                }
                _context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public async Task <T> InsertEntityAsync(T product)
        {
            _context.Attach(product);
            _context.Add(product);
            await _context.SaveChangesAsync();

            var insertedEntity = await _context.Set <T>()
                                 .AsNoTracking()
                                 .OrderByDescending(entity => entity.Id)
                                 .FirstAsync();

            return(insertedEntity);
        }
Ejemplo n.º 5
0
        public async Task <Unit> Handle(DeleteStoreCommand request, CancellationToken cancellationToken)
        {
            #region [Use repository pattern]
            var store = new Store {
                Id = request.StoreId
            };
            _context.Attach(store);
            _context.Remove(store);
            await _context.SaveChangesAsync();

            #endregion

            await _mediator.Publish(new StoreListUpdateEvent());

            return(Unit.Value);
        }