public OperationResult CreateOrderToGoWithPackage(ServiceDataContracts.OrderToGo orderToGo) { try { log.Debug($"CreateOrderToGoWithPackage"); var otg = Mapper.Map <ServiceDataContracts.OrderToGo, Entities.OrderToGo>(orderToGo); otg.UpdatedDate = DateTime.Now; otg.LastUpdatedSession = orderToGo.LastUpdatedSession; db.OrderToGo.Add(otg); db.SaveChanges(); OrderCustomrInfoService srv = new OrderCustomrInfoService(db); //srv.RecalcCustomerInfo(orderToGo.OrderCustomerId.GetValueOrDefault()); srv.RecalcCustomerAllInfo(); return(new OperationResult { Success = true, CreatedObjectId = otg.Id }); } catch (Exception e) { log.Error($"CreateOrderToGoWithPackage {e.Message}"); return(new OperationResult { Success = false, CreatedObjectId = 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); } }
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 }); } }
public OperationResult UpdateOrderToGo(ServiceDataContracts.OrderToGo orderToGo) { var order = db.OrderToGo.FirstOrDefault(o => o.Id == orderToGo.Id); if (order == null) { return(new OperationResult { Success = false, ErrorMessage = "OrderFlight Not Found." }); } order.OldId = orderToGo.OldId; order.OrderCustomerId = orderToGo.OrderCustomerId; // order.Comment = orderToGo.Comment; order.DeliveryDate = orderToGo.DeliveryDate; //order.DeliveryPlaceId = orderToGo.DeliveryPlaceId; order.DriverId = orderToGo.DriverId; order.IsSHSent = orderToGo.IsSHSent; order.ExportTime = orderToGo.ExportTime; //order.ExtraCharge = orderToGo.ExtraCharge; order.CommentKitchen = orderToGo.CommentKitchen; order.OrderComment = orderToGo.OrderComment; order.OrderNumber = orderToGo.OrderNumber; order.OrderStatus = (int)orderToGo.OrderStatus; order.PhoneNumber = orderToGo.PhoneNumber; order.ReadyTime = orderToGo.ReadyTime; //order.WhoDeliveredPersonPersonId = orderToGo.WhoDeliveredPersonPersonId; order.MarketingChannelId = orderToGo.MarketingChannelId; order.OrderCustomerId = orderToGo.OrderCustomerId; order.Closed = orderToGo.Closed; order.CreationDate = orderToGo.CreationDate == null ? DateTime.Now : orderToGo.CreationDate.Value; order.CreatedById = orderToGo.CreatedById; order.Summ = orderToGo.Summ; order.DeliveryPrice = orderToGo.DeliveryPrice; order.AddressId = orderToGo.AddressId; order.PreCheckPrinted = orderToGo.PreCheckPrinted; order.NeedPrintFR = orderToGo.NeedPrintFR; order.FRPrinted = orderToGo.FRPrinted; order.NeedPrintPrecheck = orderToGo.NeedPrintPrecheck; order.PaymentId = orderToGo.PaymentId; if (orderToGo.CreationDate != null) { order.CreationDate = orderToGo.CreationDate.Value; } order.DiscountPercent = orderToGo.DiscountPercent; Entities.LogItem logItem = new Entities.LogItem(); if (orderToGo.DishPackages != null) { UpdateDishesForOrder(orderToGo, order, 1); } //order.UpdatedDate = DateTime.Now; order.UpdatedDate = DateTime.Now; order.LastUpdatedSession = order.LastUpdatedSession; db.SaveChanges(); OrderCustomrInfoService srv = new OrderCustomrInfoService(db); srv.RecalcCustomerInfo(orderToGo.OrderCustomerId.GetValueOrDefault()); //srv.RecalcCustomerAllInfo(); return(new OperationResult { Success = true, CreatedObjectId = order.Id }); }