public OrderDetail CreateDetail(string courseTC, string trackTC, string priceTypeTC) { var cityTC = UserSettingsService.CityTC; var customerType = OrderCustomerType.PrivatePerson; if (AuthService.CurrentUser != null) { customerType = OrderCustomerType.GetType(AuthService.CurrentUser.IsCompany); } var prices = PriceService.GetAllPricesForCourseFilterByCustomerTye(courseTC, customerType, trackTC); var price = prices.FirstOrDefault(p => p.PriceType_TC == priceTypeTC); if (price == null) { price = prices.AsQueryable().GetDefault(); } if (price == null) { return(null); } var orderDetail = new OrderDetail { Course_TC = courseTC, Track_TC = trackTC, PriceType_TC = price.GetOrDefault(x => x.PriceType_TC), Price = price.GetOrDefault(x => x.Price), Duration = price.GetOrDefault(x => x.StudyMonths), Count = 1, City_TC = cityTC, }; AddObligatoryExtras(orderDetail); return(orderDetail); }
private EditCourseVM GetCourseVM(OrderDetail orderDetail, bool isTrackCourse) { var courseTC = orderDetail.Track_TC ?? orderDetail.Course_TC; var prices = PriceService.GetAllPricesForCourseFilterByCustomerTye( courseTC, orderDetail.Order.CustomerType, null); var cityTC = Cities.Moscow; if (orderDetail.Group != null) { cityTC = orderDetail.Group.BranchOffice.TrueCity_TC; } else if (orderDetail.City_TC != null) { cityTC = orderDetail.City_TC; } var editCourseVM = new EditCourseVM(CityService.GetPrefixList()) { Cities = FilterCityByPrices(CityService .GetAll().ToList(), prices.ToList()), CityTC = cityTC, /*PriceListTypes.GetCityTC(orderDetail.PriceType.PriceListType_TC) * ?? Cities.Moscow*/ OrderDetail = orderDetail, Prices = prices.OrderBy(p => p.Price).ToList() }; if (PriceTypes.IsDistanceOrWebinar(orderDetail.PriceType_TC)) { editCourseVM.CityTC = Cities.Moscow; } if (orderDetail.Track_TC == null) { var groups = GroupService .GetGroupsForCourse(courseTC) .ToList(); var webinarOnlyGroups = GroupService.WebinarOnly().Where(x => x.Course_TC == courseTC).ToList(); groups.AddRange(webinarOnlyGroups); editCourseVM.Groups = groups.OrderBy(g => g.DateBeg).ToList(); } else if (isTrackCourse) { editCourseVM.Groups = GroupService .GetGroupsForCourseByPriceType(orderDetail.Course_TC, orderDetail.PriceType_TC, orderDetail.City_TC) .OrderBy(g => g.DateBeg).ToList(); } else { editCourseVM.Groups = new List <Group>(); } editCourseVM.IsBusiness = PriceTypes.IsBusiness(orderDetail.PriceType_TC); if (PriceTypes.IsDistanceOrWebinar(orderDetail.PriceType_TC)) { editCourseVM.PriceTypeTC = PriceTypes.Webinar; } if (orderDetail.Group.GetOrDefault(x => x.IsIntraExtramural)) { editCourseVM.PriceTypeTC = PriceTypes.IntraExtra; } if (PriceTypes.IsIndividual(orderDetail.PriceType_TC)) { editCourseVM.PriceTypeTC = PriceTypes.Individual; } if (editCourseVM.PriceTypeTC == null) { editCourseVM.PriceTypeTC = string.Empty; } return(editCourseVM); }
public void UpdateOrder(string customerType) { var order = OrderService.GetCurrentOrder(); if (order == null) { return; } // var newPriceTypePart = PriceTypes.GetByCustomerType(customerType); /* string prevPriceTypePart; * if (order.CustomerType == null) * prevPriceTypePart = newPriceTypePart;*/ // var prevPriceTypePart = PriceTypes.GetByCustomerType( // OrderCustomerType.GetOpposite(customerType)); order.CustomerType = customerType; if (customerType == OrderCustomerType.PrivatePerson) { /* order.NumberOfStudents = null; * order.StudentFIOs = null;*/ } var forDelete = new List <decimal>(); foreach (var orderDetail in order.OrderDetails.Where(x => !x.IsTestCert)) { if (orderDetail.Group_ID.HasValue) { orderDetail.PriceType_TC = OrderService.GetPriceTypeForGroup( orderDetail.Group, PriceTypes.IsBusiness(orderDetail.PriceType_TC), order.CustomerType); } else { orderDetail.PriceType_TC = null; } var prices = PriceService .GetAllPricesForCourseFilterByCustomerTye(orderDetail.Course_TC, order.CustomerType, orderDetail.Track_TC).AsQueryable(); PriceView price = null; if (orderDetail.PriceType_TC != null) { price = prices .FirstOrDefault(p => p.PriceType_TC == orderDetail.PriceType_TC); } if (price != null) { orderDetail.Price = price.Price; } else { var maxPrice = prices.GetDefault(); if (maxPrice == null) { forDelete.Add(orderDetail.OrderDetailID); } else { orderDetail.Price = maxPrice.Price; orderDetail.PriceType_TC = maxPrice.PriceType_TC; } } } foreach (var forDeleteId in forDelete) { order.OrderDetails.Remove(order.OrderDetails.First(x => x.OrderDetailID == forDeleteId)); } OrderService.SubmitChanges(); UpdateDiscount(true); }