コード例 #1
0
        public void SaveOrder(Context.Order order, List <Context.OrderProduct> products)
        {
            var context = _Services.GetService(typeof(OrderDomainContext)) as OrderDomainContext;

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.Order.Add(order);

                    context.SaveChanges();

                    foreach (var product in products)
                    {
                        context.OrderProduct.Add(product);
                    }

                    context.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
コード例 #2
0
 public Domain.Model.Order GetOrderById(int orderId)
 {
     _logger.LogInformation($"Retrieving order id: {orderId}");
     if (orderId == 0)
     {
         _logger.LogInformation($"Order id is 0, returning null for order.");
         return(null);
     }
     Context.Order returnOrder = _dbContext.Orders
                                 .Include(p => p.Person)
                                 .Include(p => p.Item)
                                 .FirstOrDefault(p => p.OrderId == orderId);
     return(Mapper.MapOrder(returnOrder));
 }
コード例 #3
0
 // Order Mapping
 public static Library.Order Map(Context.Order order) => new Library.Order
 {
     Id         = order.Id,
     UserId     = order.UserId,
     LocationId = order.LocationId,
     DateTime   = (DateTime)order.DateTime,
     Price      = order.Price,
     PizzaId1   = order.PizzaId1,
     PizzaId2   = order.PizzaId2,
     PizzaId3   = order.PizzaId3,
     PizzaId4   = order.PizzaId4,
     PizzaId5   = order.PizzaId5,
     PizzaId6   = order.PizzaId6,
     PizzaId7   = order.PizzaId7,
     PizzaId8   = order.PizzaId8,
     PizzaId9   = order.PizzaId9,
     PizzaId10  = order.PizzaId10,
     PizzaId11  = order.PizzaId11,
     PizzaId12  = order.PizzaId12
 };
コード例 #4
0
        public void AddOrder(Domain.Model.Order inputOrder)
        {
            if (inputOrder.Id != 0)
            {
                _logger.LogWarning($"Order to be added has an ID ({inputOrder.Id}) already: ignoring.");
            }

            _logger.LogInformation("Adding order");

            Context.Order entity = new Context.Order
            {
                PersonId        = inputOrder.UserId,
                OrderDate       = inputOrder.Date,
                TotalOrderPrice = inputOrder.Price,
            };
            entity.OrderId = 0; //_dbContext.Orders.Max(p => p.OrderId)+1;
            _dbContext.Add(entity);
            Save();
            foreach (var val in inputOrder.Items)
            {
                val.OrderId = _dbContext.Orders.Max(p => p.OrderId);
                Repo.UpdateItem(val);
            }
        }
コード例 #5
0
 public void DeleteOrderById(int orderId)
 {
     _logger.LogInformation($"Deleting order with ID {orderId}");
     Context.Order entity = _dbContext.Orders.Find(orderId);
     _dbContext.Remove(entity);
 }