public void takeOrderInWork(BoundBookingModel model)
 {
     using (var transaction = context.Database.BeginTransaction())
     {
         try
         {
             Booking element = context.Bookings.Include(rec => rec.Customer).FirstOrDefault(rec => rec.ID == model.ID);
             if (element == null)
             {
                 throw new Exception("Элемент не найден");
             }
             var productComponents = context.OutputElements
                                     .Include(rec => rec.Element)
                                     .Where(rec => rec.OutputID == element.OutputID);
             // списываем
             foreach (var productComponent in productComponents)
             {
                 int countOnStocks   = productComponent.Count * element.Count;
                 var stockComponents = context.ReserveElements
                                       .Where(rec => rec.ElementID == productComponent.ElementID);
                 foreach (var stockComponent in stockComponents)
                 {
                     // компонентов на одном слкаде может не хватать
                     if (stockComponent.Count >= countOnStocks)
                     {
                         stockComponent.Count -= countOnStocks;
                         countOnStocks         = 0;
                         context.SaveChanges();
                         break;
                     }
                     else
                     {
                         countOnStocks       -= stockComponent.Count;
                         stockComponent.Count = 0;
                         context.SaveChanges();
                     }
                 }
                 if (countOnStocks > 0)
                 {
                     throw new Exception("Не достаточно компонента " +
                                         productComponent.Element.ElementName + " требуется " +
                                         productComponent.Count + ", не хватает " + countOnStocks);
                 }
             }
             element.ExecutorID      = model.ExecutorID;
             element.DateOfImplement = DateTime.Now;
             element.Status          = StatusOfBooking.Выполняемый;
             context.SaveChanges();
             Customer customer = context.Customers.FirstOrDefault(x => x.ID == element.CustomerID);
             SendEmail(customer.Mail, "Оповещение по заказам",
                       string.Format("Заказ №{0} от {1} передеан в работу", element.ID, element.DateOfCreate.ToShortDateString()));
             transaction.Commit();
         }
         catch (Exception)
         {
             transaction.Rollback();
             throw;
         }
     }
 }
예제 #2
0
        public void createOrder(BoundBookingModel model)
        {
            int maxId = source.Bookings.Count > 0 ? source.Bookings.Max(rec => rec.ID) : 0;

            source.Bookings.Add(new Booking
            {
                ID           = maxId + 1,
                CustomerID   = model.CustomerID,
                OutputID     = model.OutputID,
                DateOfCreate = DateTime.Now,
                Count        = model.Count,
                Summa        = model.Summa,
                Status       = StatusOfBooking.Принятый
            });
        }
예제 #3
0
        public void takeOrderInWork(BoundBookingModel model)
        {
            Booking element = source.Bookings.FirstOrDefault(rec => rec.ID == model.ID);

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            var productComponents = source.OutputElements.Where(rec => rec.OutputID == element.OutputID);

            foreach (var productComponent in productComponents)
            {
                int countOnStocks = source.ReserveElements
                                    .Where(rec => rec.ElementID == productComponent.ElementID)
                                    .Sum(rec => rec.Count);
                if (countOnStocks < productComponent.Count * element.Count)
                {
                    var componentName = source.Elements
                                        .FirstOrDefault(rec => rec.ID == productComponent.ElementID);
                    throw new Exception("Не достаточно компонента " + componentName?.ElementName +
                                        " требуется " + productComponent.Count + ", в наличии " + countOnStocks);
                }
            }
            foreach (var productComponent in productComponents)
            {
                int countOnStocks   = productComponent.Count * element.Count;
                var stockComponents = source.ReserveElements
                                      .Where(rec => rec.ElementID == productComponent.ElementID);
                foreach (var stockComponent in stockComponents)
                {
                    if (stockComponent.Count >= countOnStocks)
                    {
                        stockComponent.Count -= countOnStocks;
                        break;
                    }
                    else
                    {
                        countOnStocks       -= stockComponent.Count;
                        stockComponent.Count = 0;
                    }
                }
            }
            element.ExecutorID      = model.ExecutorID;
            element.DateOfImplement = DateTime.Now;
            element.Status          = StatusOfBooking.Выполняемый;
        }
        public void createOrder(BoundBookingModel model)
        {
            var order = new Booking
            {
                CustomerID   = model.CustomerID,
                OutputID     = model.OutputID,
                DateOfCreate = DateTime.Now,
                Count        = model.Count,
                Summa        = model.Summa,
                Status       = StatusOfBooking.Принятый
            };

            context.Bookings.Add(order);
            context.SaveChanges();

            var client = context.Customers.FirstOrDefault(x => x.ID == model.CustomerID);

            SendEmail(client.Mail, "Оповещение по заказам",
                      string.Format("Заказ №{0} от {1} создан успешно", order.ID,
                                    order.DateOfCreate.ToShortDateString()));
        }
예제 #5
0
 public void PayBooking(BoundBookingModel model)
 {
     _service.payOrder(model.ID);
 }
예제 #6
0
 public void FinishBooking(BoundBookingModel model)
 {
     _service.finishOrder(model.ID);
 }
예제 #7
0
 public void TakeBookingInWork(BoundBookingModel model)
 {
     _service.takeOrderInWork(model);
 }
예제 #8
0
 public void CreateBooking(BoundBookingModel model)
 {
     _service.createOrder(model);
 }