Ejemplo n.º 1
0
            protected override async Task Handle(Command request, CancellationToken cancellationToken)
            {
                List <Infastructure.Entities.Weapon> weapons = new List <Infastructure.Entities.Weapon>();

                weapons = JsonSerializer.Deserialize <List <Infastructure.Entities.Weapon> >(request.Value);

                Infastructure.Entities.Order order = new Infastructure.Entities.Order
                {
                    Date  = DateTime.Now, Count = weapons.Count,
                    Price = weapons.Sum(x => x.Price),
                    User  = _context.Users.FirstOrDefault(x => x.UserName == request.UseName)
                };

                await _context.Orders.AddAsync(order);

                _context.SaveChanges();

                foreach (var weapon in weapons)
                {
                    await _context.AddAsync(new Infastructure.Entities.OrderWeapon {
                        OrderId = order.Id, WeaponId = weapon.Id
                    });
                }

                _context.SaveChanges();
            }
 public async Task Add <T>(T entity) where T : class
 {
     await _context.AddAsync(entity);
 }