Exemple #1
0
        public void Update(EditCourseVM model)
        {
            var newDetail   = model.OrderDetail;
            var order       = OrderService.GetCurrentOrder();
            var orderDetail = order.OrderDetails
                              .First(od => od.OrderDetailID == newDetail.OrderDetailID);

            if (model.IsTrackCourse)
            {
                UpdateTrackGroup(newDetail, orderDetail);
            }
            else if (orderDetail.Track_TC != null)
            {
                UpdateTrackPrices(order, orderDetail.Track_TC, model.PriceTypeTC,
                                  newDetail, model.CityTC);
            }
            else
            {
                UpdateCourse(model, newDetail, orderDetail);
            }
            orderDetail.ClearDiscount();
            orderDetail.SeatNumber = null;
            var extrases             = ExtrasService.GetFor(orderDetail).Select(x => x.Extras_ID);
            var notAvailableExtrases = orderDetail.OrderExtras.Where(
                od => !extrases.Contains(od.Extras_ID)).ToList();

            for (int i = 0; i < notAvailableExtrases.Count; i++)
            {
                var notAvailable = notAvailableExtrases[i];
                orderDetail.OrderExtras.Remove(notAvailable);
            }

            OrderService.SubmitChanges();
        }
Exemple #2
0
        void AddObligatoryExtras(OrderDetail orderDetail)
        {
            var extras = ExtrasService.Travel().GetValueOrDefault(orderDetail.Course_TC);

            if (extras != null)
            {
                var extrasId = extras.Extras_ID;
                orderDetail.OrderExtras.Add(new OrderExtras {
                    Extras_ID = extrasId,
                    Price     = ExtrasService.GetPrice(extrasId)
                });
            }
        }
Exemple #3
0
        public bool AddForeignDelivery(OrderDetail orderDetail)
        {
            var user = AuthService.CurrentUser;

            if (orderDetail.IsTestCert && orderDetail.Params.IsPaper && user != null && user.GetAddress() != null &&
                user.GetAddress().CountryID != Countries.Russian)
            {
                if (orderDetail.OrderExtras.All(x => x.Extras_ID != Extrases.ForeignDelivery))
                {
                    orderDetail.OrderExtras.Add(new OrderExtras {
                        Extras_ID = Extrases.ForeignDelivery,
                        Price     = ExtrasService.GetPrice(Extrases.ForeignDelivery)
                    });
                }
                return(true);
            }
            return(false);
        }
Exemple #4
0
        public OrderDetail CreateTestCertDetail(int userTestId)
        {
            var orderDetail =
                new OrderDetail
            {
                Course_TC    = CourseTC.Srt,
                Price        = ExtrasService.GetPrice(Extrases.TestCertificte),
                UserTestId   = userTestId,
                PriceType_TC = PriceTypes.PrivatePersonWeekend,
                Count        = 1,
            };

            orderDetail.Params.Type = TestCertType.Papper;
            orderDetail.Params.Lang = TestCertLang.Eng;
            orderDetail.UpdateXmlParams();
            AddForeignDelivery(orderDetail);
            return(orderDetail);
        }
Exemple #5
0
        public CartVM GetCart(decimal?orderId = null, bool addTrackDiscounts = false)
        {
            Entities.Context.Order order = null;
            Entities.Context.Order planOrder;
            if (orderId.HasValue)
            {
                order     = OrderService.GetByPK(orderId.Value);
                planOrder = OrderService.GetCurrentOrder(true) ?? new Entities.Context.Order();
            }
            else
            {
                order     = OrderService.GetCurrentOrder() ?? new Entities.Context.Order();
                planOrder = OrderService.GetCurrentOrder(true) ?? new Entities.Context.Order();
            }

            var trainer = EmployeeService.AllEmployees().GetValueOrDefault(order.FavoriteTeacher1);

            var cart = new CartVM(order)
            {
                InPlan     = new OrderSeparator(planOrder),
                User       = AuthService.CurrentUser,
                FavTrainer = trainer.GetOrDefault(x => x.FullName)
            };

            if (cart.OnlyIsCompaty &&
                order.CustomerType == OrderCustomerType.PrivatePerson)
            {
                UpdateOrder(OrderCustomerType.Organization);
            }

            cart.CourseTCHasExtrases = order.OrderDetails.Where(od => od.Track_TC == null &&
                                                                ExtrasService.GetFor(od).Any()).Select(od => od.Course_TC).ToList();

            cart.ExtrasTexts = ExtrasService.Texts();
            cart.IsNearestGroupOrderDetails = order.OrderDetails.Where(x =>
                                                                       x.Group_ID.HasValue && GroupService.GetGroupsForCourse(x.Course_TC)
                                                                       .FirstOrDefault().GetOrDefault(g => g.Group_ID == x.Group_ID))
                                              .Select(x => x.OrderDetailID).ToList();

            if (addTrackDiscounts && order.CustomerType != OrderCustomerType.Organization &&
                !cart.OnlyIsCompaty)
            {
                var trackInCart = order.OrderDetails.Where(x => x.Track_TC != null).Select(x => x.Track_TC).ToList();
                var courseTCs   = order.OrderDetails.Where(x => x.Track_TC.IsEmpty()).Select(x => x.Course_TC).ToList();
                if (courseTCs.Any())
                {
                    var trackCourses = CourseService.GetActiveTrackCourses().Select(x =>
                                                                                    new { x.Key, CourseCount = x.Value.Intersect(courseTCs).Count() })
                                       .Where(x => x.CourseCount > 0).ToDictionary(x => x.Key, x => x.CourseCount);
                    var trackTCs       = trackCourses.Select(x => x.Key).Where(tc => !trackInCart.Contains(tc)).ToList();
                    var tracks         = CourseService.GetAll(x => trackTCs.Contains(x.Course_TC)).ToList();
                    var trackDiscounts = TrackService.GetTrackDiscounts(tracks)
                                         .OrderByDescending(x => trackCourses[x.Track.Course_TC]).ThenBy(x => x.Price);
                    cart.TrackDiscounts = trackDiscounts.ToList();
                }

                var allOrderCourseTCs = order.OrderDetails.Select(x => x.Course_TC).ToList();
                cart.WithWebinar =
                    allOrderCourseTCs.Where(x => PriceService.GetAllPricesForCourse(x, null).Any(y => y.IsWebinar)).ToList();
            }

            return(cart);
        }