Esempio n. 1
0
        private void UpdateDishesForOrder(ServiceDataContracts.OrderToGo orderToGo, Entities.OrderToGo originalOrder, long userId)
        {
            log.Info("UpdateDishesForOrder");

            // Delete not presented packages
            foreach (var package in originalOrder.DishPackages.ToList())
            {
                if (!orderToGo.DishPackages.Any(dp => dp.Id == package.Id))
                {
                    log.Info("Delete not presented packages");
                    log.Info("Dish Id: " + package.DishId);
                    var packageToDelete = db.DishPackagesToGoOrder.First(p => p.Id == package.Id);
                    db.DishPackagesToGoOrder.Remove(packageToDelete);
                    // db.SaveChanges();
                }
            }

            var ds = new DishPackageToGoOrderService(db);

            // Add New packages
            foreach (var package in orderToGo.DishPackages.ToList())
            {
                if (package.Id == 0)
                {
                    log.Info("Add new packages");
                    log.Info("ADish Id: " + package.DishId);

                    ds.CreateDishPackageToGoOrder(package);
                }
            }

            // Update presented packages
            foreach (var package in orderToGo.DishPackages.ToList())
            {
                ds.UpdateDishPackageToGoOrder(package);
            }
        }
Esempio n. 2
0
        public OperationResult CreateOrderToGo(ServiceDataContracts.OrderToGo orderToGo)
        {
            try
            {
                var otg = new Entities.OrderToGo();

                otg.OldId = orderToGo.OldId;

                // otg.Comment = orderToGo.Comment;
                otg.DriverId     = orderToGo.DriverId;
                otg.DeliveryDate = orderToGo.DeliveryDate;
                // otg.DeliveryPlaceId = orderToGo.DeliveryPlaceId;
                otg.ExportTime = orderToGo.ExportTime;
                //otg.ExtraCharge = orderToGo.ExtraCharge;
                otg.IsSHSent       = orderToGo.IsSHSent;
                otg.CommentKitchen = orderToGo.CommentKitchen;
                otg.OrderComment   = orderToGo.OrderComment;
                otg.OrderNumber    = orderToGo.OrderNumber;
                otg.OrderStatus    = (int)orderToGo.OrderStatus;
                otg.PhoneNumber    = orderToGo.PhoneNumber;
                otg.ReadyTime      = orderToGo.ReadyTime;
                //otg.WhoDeliveredPersonPersonId = orderToGo.WhoDeliveredPersonPersonId;

                otg.MarketingChannelId = orderToGo.MarketingChannelId;
                otg.OrderCustomerId    = orderToGo.OrderCustomerId;

                otg.CreatedById = orderToGo.CreatedById;

                otg.CreationDate  = orderToGo.CreationDate == null ? DateTime.Now : orderToGo.CreationDate.Value;
                otg.Summ          = orderToGo.Summ;
                otg.DeliveryPrice = orderToGo.DeliveryPrice;

                otg.PaymentId = orderToGo.PaymentId;

                otg.DiscountPercent = orderToGo.DiscountPercent;


                otg.AddressId         = orderToGo.AddressId;
                otg.PreCheckPrinted   = orderToGo.PreCheckPrinted;
                otg.NeedPrintFR       = orderToGo.NeedPrintFR;
                otg.FRPrinted         = orderToGo.FRPrinted;
                otg.Closed            = orderToGo.Closed;
                otg.NeedPrintPrecheck = orderToGo.NeedPrintPrecheck;


                otg.UpdatedDate        = DateTime.Now;
                otg.LastUpdatedSession = orderToGo.LastUpdatedSession;
                db.OrderToGo.Add(otg);
                db.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = otg.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }