protected virtual void SetViewModelContext( ProductViewModel productViewModel, VariantViewModel selectedVariantVm, IEnumerable <VariantViewModel> allVariantsVm) { //TODO: Move this to final mapping step? productViewModel.Context["productId"] = productViewModel.ProductId; if (selectedVariantVm != null) { productViewModel.Context["allVariants"] = allVariantsVm.Select(v => new { v.ListPrice, v.Id, v.Kvas, v.Sku }); productViewModel.Context["selectedVariantId"] = selectedVariantVm.Id; productViewModel.Context["displayedVariantId"] = selectedVariantVm.Id; } //Some additionnal Context Required by JS productViewModel.Context["CategoryId"] = productViewModel.CategoryId; productViewModel.Context["Sku"] = productViewModel.Sku; productViewModel.Context["keyVariantAttributeItems"] = productViewModel.KeyVariantAttributeItems; productViewModel.Context["CreateAccountUrl"] = productViewModel.CreateAccountUrl; // Transfer custom properties that might have been added foreach (var property in productViewModel.Bag) { productViewModel.Context[property.Key] = property.Value; } }
public async Task <IActionResult> RegisterConfirmed(int?variantId, IList <int> sIds) { if (variantId == null || !sIds.Any()) { return(BadRequest()); } if (ModelState.IsValid) { var variant = (await _variantRepository.GetVariantById(variantId.Value)); if (variant == null) { return(NotFound()); } var students = await Task.WhenAll(sIds.Select(id => _studentRepository.GetStudentById(id) )); if (students != null) { var studentsPostDto = students.Select(StudentViewModel.CreateStudentPostDto).ToList(); var registrationDto = VariantViewModel.CreateRegistrationDto(variant); var registeredIds = await WisClient.RegisterStudents(studentsPostDto, registrationDto); foreach (var registeredId in registeredIds) { await _studentRepository.RegisterStudent(registeredId); await _studentRepository.SaveChanges(); } } } return(RedirectToAction(nameof(Index))); }
public List <VariantViewModel> GetSelected() { List <VariantViewModel> Listvartient = new List <VariantViewModel>(); foreach (var items in obj.Carts) { var objVVM = new VariantViewModel(); var id = items.VariantId; var ThatVarient = obj.Variants.Find(id); objVVM.Image = ThatVarient.Product.Image; objVVM.Name = ThatVarient.Product.Name; objVVM.Description = ThatVarient.Product.Description; objVVM.Category = ThatVarient.Product.Category; objVVM.Size = ThatVarient.Size; objVVM.Color = ThatVarient.Color; objVVM.Price = ThatVarient.Price; objVVM.Count = items.Count; objVVM.TotalPrice = items.TotalPrice; objVVM.CartId = items.CartId; Listvartient.Add(objVVM); } return(Listvartient); }
public async Task <IActionResult> Variant(int optionId) { try { if (User.Identity.IsAuthenticated) { var user = await _userManager.GetUserAsync(User); ViewBag.Name = user.Name; } var option = _optionService.GetOption(optionId); var subject = _subjectService.GetSubject(option.SubjectId); var whoAdd = _userService.GetUserNameById(option.UserId); ViewBag.Subject = subject.Name; var problemOptions = _optionService.GetProblemOptions(option.Id); var model = new VariantViewModel { UserName = whoAdd, SubjectId = subject.Id }; foreach (var po in problemOptions) { var problem = _problemService.GetProblem(po.ProblemId); model.Problems.Add(problem); model.Pictures.AddRange(_pictureService.GetPicturesByProblemId(problem.Id)); } return(View(model)); } catch (Exception exc) { return(base.RedirectToAction("Error", "Home", new ErrorViewModel { Message = exc.Message })); } }
// GET: CheckOut public ActionResult Index() { var cartObj = db.Carts; List <VariantViewModel> Listvartient = new List <VariantViewModel>(); foreach (var items in cartObj) { var objVVM = new VariantViewModel(); var id = items.VariantId; var ThatVarient = db.Variants.Find(id); objVVM.Image = ThatVarient.Product.Image; objVVM.Name = ThatVarient.Product.Name; objVVM.Description = ThatVarient.Product.Description; objVVM.Category = ThatVarient.Product.Category; objVVM.Size = ThatVarient.Size; objVVM.Color = ThatVarient.Color; objVVM.Price = ThatVarient.Price; objVVM.Count = items.Count; objVVM.TotalPrice = items.TotalPrice; objVVM.CartId = items.CartId; Listvartient.Add(objVVM); } return(View(Listvartient)); }
/// <summary> /// Creates a product view model based on an Item and Rendering /// </summary> /// <param name="productItem">The product item to based the model on</param> /// <param name="rendering">The rendering to initialize the model with</param> /// <returns>A Product View Model</returns> protected ProductViewModel GetProductViewModel(Item productItem, Rendering rendering) { if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null) { return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]); } var variants = new List <VariantViewModel>(); if (productItem != null && productItem.HasChildren) { foreach (Item item in productItem.Children) { var v = new VariantViewModel(item); variants.Add(v); } } var productViewModel = new ProductViewModel(); productViewModel.Initialize(rendering, variants); PopulateStockInformation(productViewModel); this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel; return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]); }
/// <summary> /// Initializes specifications for a given variant. /// </summary> /// <param name="productId">ID of the product.</param> /// <param name="productImages">Available product images.</param> /// <param name="cultureInfo">Culture info.</param> /// <param name="variantViewModel">ViewModel to be impacted.</param> protected virtual void InitializeVariantSpecificaton( Overture.ServiceModel.Products.Product product, ProductDefinition productDefinition, VariantViewModel variantViewModel) { variantViewModel.Specifications = ProductSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam { VariantId = variantViewModel.Id, Product = product, ProductDefinition = productDefinition }); }
public async Task <Data.Variant> CreateVariantAsync(VariantViewModel model) { var variant = new Data.Variant() { Value = model.Value, Id = model.Id, CreatedAt = model.CreatedAt, IsDeleted = false, VariantType = model.VariantType }; return(await _variantManager.CreateVariantAsync(variant)); }
/// <summary> /// Initializes image fields for a given variant. /// </summary> /// <param name="productId">ID of the product.</param> /// <param name="productImages">Available product images.</param> /// <param name="cultureInfo">Culture info.</param> /// <param name="variantViewModel">ViewModel to be impacted.</param> protected virtual void InitializeVariantImages( string productId, IEnumerable <AllProductImages> productImages, CultureInfo cultureInfo, VariantViewModel variantViewModel) { var images = BuildImages(productId, variantViewModel.Id, variantViewModel.DisplayName, productImages, cultureInfo).ToList(); var selectedImage = images.Find(i => i.Selected) ?? images.FirstOrDefault(); variantViewModel.Images = images; variantViewModel.SelectedImage = selectedImage; variantViewModel.FallbackImageUrl = selectedImage != null ? selectedImage.FallbackImageUrl : string.Empty; }
public ProductViewModel GetGiftCardViewModel(Item productItem, Rendering currentRendering) { if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null) { return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]); } var variants = new List <VariantViewModel>(); if (productItem != null && productItem.HasChildren) { foreach (Item item in productItem.Children) { var v = new VariantViewModel(item); variants.Add(v); } } var productViewModel = new ProductViewModel(productItem); productViewModel.Initialize(currentRendering, variants); productViewModel.ProductName = productViewModel.DisplayName; if (this.CurrentSiteContext.UrlContainsCategory) { productViewModel.ParentCategoryId = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl(); var category = this.CatalogManager.GetCategory(productViewModel.ParentCategoryId); if (category != null) { productViewModel.ParentCategoryName = category.DisplayName; } } //Special handling for gift card if (productViewModel.ProductId == StorefrontManager.CurrentStorefront.GiftCardProductId) { productViewModel.GiftCardAmountOptions = GetGiftCardAmountOptions(productViewModel); } else { this.CatalogManager.GetProductPrice(this.CurrentVisitorContext, productViewModel); productViewModel.CustomerAverageRating = this.CatalogManager.GetProductRating(productItem); } this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel; return(productViewModel); }
public ActionResult Details(int?id) { if (Session["EmailId"] == null) { return(RedirectToAction("MessageDetails")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var variants = new List <VariantViewModel>(); Product product = db.Products.Find(id); if (product == null) { return(HttpNotFound()); } if (Session["EmailId"] != null) { foreach (var variant in product.Variants) { var v = new VariantViewModel { Id = variant.VariantId, ProductId = product.ProductId, Name = product.Name, Image = product.Image, Category = product.Category, Description = product.Description, Size = variant.Size, Color = variant.Color, AvailableQty = variant.AvailableQty, Price = variant.Price, Checked = false }; variants.Add(v); } return(View(variants)); } return(RedirectToAction("Login", "Account")); }
public ActionResult ShowVariant(Guid variantID) { try { ModelState.Clear(); VariantDTO variantDTO = productBusinessContext.GetVariant(variantID); ProductDTO productDTO = productBusinessContext.GetProduct(variantDTO.Product.ID); VariantViewModel variantViewModel = ProductViewModelMapper.Map <VariantDTO, VariantViewModel>(variantDTO); ProductViewModel productViewModel = ProductViewModelMapper.Map <ProductDTO, ProductViewModel>(productDTO); productViewModel.variantDisplay = variantViewModel; return(View(productViewModel)); }catch (Exception ex) { return(RedirectToAction("ExceptionCatch", "Static", new { exception = ex })); } }
// GET: Variants/Create public async Task <IActionResult> Create(CourseViewModel courseVm, int?itemId, int?points) { if (!ModelState.IsValid || courseVm == null || itemId == null || points == null) { return(BadRequest()); } var variantsDto = await WisClient.GetVariantsAsync(courseVm.WisId, itemId.Value); if (variantsDto == null) { return(NotFound()); } var variantsVm = variantsDto.Select(v => VariantViewModel.CreateVariantVm(v, itemId.Value, points.Value, courseVm)); return(View(variantsVm)); }
//[HttpPost] public ActionResult UpdateVariant(Guid variantID) { try { Guid VariantID = variantID; ProductViewModel productViewModel = new ProductViewModel(); VariantDTO variantDTO = productBusinessContext.GetVariant(VariantID); VariantViewModel variantViewModel = ProductProductVMMapper.Map <VariantDTO, VariantViewModel>(variantDTO); ProductDTO productDTO = productBusinessContext.GetProduct(variantDTO.Product.ID); productViewModel = CategoryProductVMMapper.Map <ProductDTO, ProductViewModel>(productDTO); productViewModel.variantDisplay = variantViewModel; return(View(productViewModel.variantDisplay)); } catch (Exception ex) { return(RedirectToAction("DefaultExceptionCatch", "Default", new { exception = ex.Message })); } }
protected virtual void MergeSelectedVariantVmToProductVm( VariantViewModel selectedVariantVm, ProductViewModel productViewModel) { if (selectedVariantVm == null) { productViewModel.Sku = productViewModel.Sku; } else { productViewModel.SelectedVariantId = selectedVariantVm.Id; productViewModel.Sku = selectedVariantVm.Sku; productViewModel.DisplayName = selectedVariantVm.DisplayName; productViewModel.ListPrice = selectedVariantVm.ListPrice; productViewModel.Images = selectedVariantVm.Images; productViewModel.SelectedImage = selectedVariantVm.SelectedImage; productViewModel.FallbackImageUrl = selectedVariantVm.FallbackImageUrl; } }
// GET: Variants/Details/id public async Task <IActionResult> Details(int?id) { if (id == null) { return(BadRequest()); } var variant = await _variantRepository .GetVariantById(id.Value); if (variant == null) { return(NotFound()); } var variantVm = VariantViewModel.CreateVariantVm(variant); return(View(variantVm)); }
/// <summary> /// update variant information on variant change. /// </summary> /// <param name="variantID"></param> /// <returns>ActionResult--> returns updated variant info</returns> public ActionResult UpdateVariant(string variantID) { try { ModelState.Clear(); Guid VariantID = new Guid(variantID); VariantDTO variantDTO = productBusinessContext.GetVariant(VariantID); ProductDTO productDTO = productBusinessContext.GetProduct(variantDTO.Product.ID); VariantViewModel variantViewModel = ProductViewModelMapper.Map <VariantDTO, VariantViewModel>(variantDTO); ProductViewModel productViewModel = ProductViewModelMapper.Map <ProductDTO, ProductViewModel>(productDTO); productViewModel.variantDisplay = variantViewModel; return(View(productViewModel.variantDisplay)); //return RedirectToAction("ShowVariant", new { variantID = variantDTO.ID }); } catch (Exception ex) { return(RedirectToAction("ExceptionCatch", "Static", new { exception = ex.Message })); } }
public ActionResult TestStarting(int testId, int questionId = 1) { var config = new MapperConfiguration(cfg => cfg.CreateMap <KnowledgeSystemDAL.Models.Question, StartingTestQuestionViewModel>()); var mapper = config.CreateMapper(); List <QuestionViewModel> questions = new List <QuestionViewModel>(); foreach (var item in questionRepository.GetAllQuestionByTestId(testId)) { QuestionViewModel questionViewModel = new QuestionViewModel(); questionViewModel.Id = item.Id; questionViewModel.Text = item.Text; questionViewModel.TestID = item.TestID; questions.Add(questionViewModel); } List <VariantViewModel> variants = new List <VariantViewModel>(); foreach (var item in variantRepository.GetAllByQuestionId(questionId)) { VariantViewModel variant = new VariantViewModel(); variant.Id = item.Id; variant.Text = item.Text; variant.IsRight = item.IsRight; variant.QuestionId = item.QuestionId; variants.Add(variant); } variants.Count(); var pageInfo = new QuestionPageInformation { TestId = testId, QuestionId = questionId, TotalPages = questionRepository.GetAllQuestionByTestId(testId).Count }; var startingQuestionViewModel = new StartingTestQuestionViewModel { QuestionPageInformation = pageInfo, Question = questions, Variants = variants }; return(View(startingQuestionViewModel)); }
private ProductViewModel GetProductViewModel(Item productItem, Rendering rendering) { if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null) { return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]); } var variants = new List <VariantViewModel>(); if (productItem != null && productItem.HasChildren) { foreach (Item item in productItem.Children) { var v = new VariantViewModel(item); variants.Add(v); } } var productViewModel = new ProductViewModel(productItem); productViewModel.Initialize(rendering, variants); productViewModel.ProductName = productViewModel.DisplayName; if (this.CurrentSiteContext.UrlContainsCategory) { productViewModel.ParentCategoryId = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl(); var category = _catalogManager.GetCategory(productViewModel.ParentCategoryId); if (category != null) { productViewModel.ParentCategoryName = category.DisplayName; } } _catalogManager.GetProductPrice(this.CurrentVisitorContext, productViewModel); productViewModel.CustomerAverageRating = _catalogManager.GetProductRating(productItem); this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel; return(productViewModel); }
/// <summary> /// Creates a product view model based on an Item and Rendering /// </summary> /// <param name="productItem">The product item to based the model on</param> /// <param name="rendering">The rendering to initialize the model with</param> /// <returns>A Product View Model</returns> protected ProductViewModel GetProductViewModel(Item productItem, Rendering rendering) { if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null) { return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]); } var variants = new List <VariantViewModel>(); if (productItem != null && productItem.HasChildren) { foreach (Item item in productItem.Children) { var v = new VariantViewModel(item); variants.Add(v); } } var productViewModel = new ProductViewModel(productItem); productViewModel.Initialize(rendering, variants); //Set Discount Info productViewModel.Discounts = this.GetProductDiscountInfo(productItem); //Special handling for gift card if (productViewModel.ProductId == StorefrontManager.CurrentStorefront.GiftCardProductId) { productViewModel.GiftCardAmountOptions = GetGiftCardAmountOptions(productViewModel); } else { this.CatalogManager.GetProductPrice(productViewModel); productViewModel.CustomerAverageRating = this.CatalogManager.GetProductRating(productItem); } this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel; return(productViewModel); }
protected virtual void SetViewModelContext( ProductViewModel productViewModel, VariantViewModel selectedVariantVm, IEnumerable <VariantViewModel> allVariantsVm) { //TODO: Move this to final mapping step? productViewModel.Context["productId"] = productViewModel.ProductId; if (selectedVariantVm != null) { productViewModel.Context["allVariants"] = allVariantsVm.Select(v => new { v.DisplayListPrice, v.Id, v.Kvas, v.Sku }); productViewModel.Context["selectedVariantId"] = selectedVariantVm.Id; productViewModel.Context["displayedVariantId"] = selectedVariantVm.Id; } //Some additionnal Context Required by JS productViewModel.Context["Brand"] = productViewModel.Brand; productViewModel.Context["DisplayName"] = productViewModel.DisplayName; productViewModel.Context["CategoryId"] = productViewModel.CategoryId; productViewModel.Context["Sku"] = productViewModel.Sku; productViewModel.Context["keyVariantAttributeItems"] = productViewModel.KeyVariantAttributeItems; productViewModel.Context["CreateAccountUrl"] = productViewModel.CreateAccountUrl; productViewModel.Context["Weight"] = productViewModel.Weight; productViewModel.Context["WeightUOM"] = productViewModel.WeightUOM; productViewModel.Context["ItemFormat"] = productViewModel.ItemFormat; productViewModel.Context["SellingMethod"] = productViewModel.SellingMethod; productViewModel.Context["UnitOfMeasure"] = productViewModel.UnitOfMeasure; productViewModel.Context["IsUnit"] = productViewModel.IsUnit; productViewModel.Context["IsUnitMeasure"] = productViewModel.IsUnitMeasure; productViewModel.Context["IsApproxUnit"] = productViewModel.IsApproxUnit; // Transfer custom properties that might have been added foreach (var property in productViewModel.Bag) { productViewModel.Context[property.Key] = property.Value; } }
public async Task <IActionResult> CreateConfirmed(VariantViewModel variantVm) { if (ModelState.IsValid) { if (!_variantRepository.VariantExists(variantVm.WisId)) { try { var variant = VariantViewModel.CreateVariant(variantVm); if (variant != null) { await _variantRepository.InsertVariant(variant); await _variantRepository.SaveChanges(); VariantViewModel.ActiveVariantId = variant.Id; } } catch (DbUpdateConcurrencyException) { } } return(RedirectToAction(nameof(Index))); } return(View()); }
/// <summary> /// Return the initial state of the KVA selector /// The default implementation initialize the KVA with the selected Variant; /// A common override is to initialize the KVA only if the selected Variant match the requested Variant /// /// </summary> /// <param name="selectedVariant"></param> /// <param name="param"></param> /// <returns></returns> protected virtual Dictionary <string, object> GetSelectedKvas( VariantViewModel selectedVariant, CreateProductDetailViewModelParam param) { return(selectedVariant == null ? new Dictionary <string, object>() : selectedVariant.Kvas); }
/// <summary> /// Creates a product view model based on an Item and Rendering /// </summary> /// <param name="productItem">The product item to based the model on</param> /// <param name="rendering">The rendering to initialize the model with</param> /// <returns>A Product View Model</returns> protected ProductViewModel GetProductViewModel(Item productItem, Rendering rendering) { if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null) { return (ProductViewModel) this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]; } var variants = new List<VariantViewModel>(); if (productItem != null && productItem.HasChildren) { foreach (Item item in productItem.Children) { var v = new VariantViewModel(item); variants.Add(v); } } var productViewModel = new ProductViewModel(); productViewModel.Initialize(rendering, variants); PopulateStockInformation(productViewModel); this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel; return (ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]; }
public ActionResult ShowOrders() { if (Session["EmailId"] == null) { return(RedirectToAction("MessageDetails")); } List <MyOrdersViewModel> ModelList = new List <MyOrdersViewModel>(); foreach (Order order in db.Orders) { if (order.PersonId.Equals(Session["EmailId"].ToString())) { MyOrdersViewModel model = new MyOrdersViewModel(); model.Address = order.Address; model.TotalAmount = order.TotalAmount; foreach (OrderedProduct variant in db.OrderedProducts) { if (variant.OrderId == order.OrderId) { var obj = (from s in db.Variants where s.VariantId == variant.VariantId select s ).Single(); var count = 0; foreach (var item in db.OrderedProducts) { if (item.VariantId == variant.VariantId && order.OrderId == variant.OrderId) { count = item.Quantity; } } var productDetail = (from s in db.Products where s.ProductId == obj.ProductId select s ).Single(); VariantViewModel VVMObj = new VariantViewModel(); VVMObj.Name = productDetail.Name; VVMObj.ProductId = productDetail.ProductId; VVMObj.Description = productDetail.Description; VVMObj.Category = productDetail.Category; VVMObj.Color = obj.Color; VVMObj.Size = obj.Size; VVMObj.Quantity = count; model.Variants.Add(VVMObj); } } ModelList.Add(model); } } return(View(ModelList)); }
public virtual ProductDetailViewModel CreateDetailsViewModel() { ProductDetailViewModel productDetailViewModel = null; var currentProduct = Ucommerce.EntitiesV2.Product.FirstOrDefault(x => x.Guid == CatalogContext.CurrentProduct.Guid); if (currentProduct != null) { var imageService = ObjectFactory.Instance.Resolve <IImageService>(); var currentCategory = CatalogContext.CurrentCategory; string displayName = string.Empty; if (currentProduct.ParentProduct != null) { displayName = $"{currentProduct.ParentProduct.DisplayName()} "; } displayName += currentProduct.DisplayName(); var productPrice = CatalogLibrary.CalculatePrices(new List <Guid>() { currentProduct.Guid }).Items .FirstOrDefault(); decimal price = 0; decimal discount = 0; if (productPrice != null) { price = productPrice.PriceExclTax; discount = productPrice.DiscountExclTax; var currentCatalog = CatalogContext.CurrentCatalog; if (currentCatalog != null && currentCatalog.ShowPricesIncludingTax) { price = productPrice.PriceInclTax; discount = productPrice.DiscountInclTax; } } var imageUrl = imageService.GetImage(currentProduct.PrimaryImageMediaId).Url; var absoluteImageUrl = UrlPath.ResolveAbsoluteUrl(imageUrl); var definition = currentProduct.ProductDefinition; var isProductFamily = definition.IsProductFamily(); productDetailViewModel = new ProductDetailViewModel() { DisplayName = displayName, Guid = currentProduct.Guid, PrimaryImageMediaUrl = absoluteImageUrl, LongDescription = currentProduct.LongDescription(), ShortDescription = currentProduct.ShortDescription(), ProductUrl = UrlService.GetUrl(CatalogContext.CurrentCatalog, CatalogContext.CurrentProduct), Price = new Money(price, CatalogContext.CurrentPriceGroup.CurrencyISOCode).ToString(), Discount = discount > 0 ? new Money(discount, CatalogContext.CurrentPriceGroup.CurrencyISOCode).ToString() : "", Sku = currentProduct.Sku, Rating = Convert.ToInt32(Math.Round(currentProduct.Rating.GetValueOrDefault())), VariantSku = currentProduct.VariantSku, IsVariant = currentProduct.IsVariant, IsProductFamily = currentProduct.ProductDefinition.IsProductFamily(), AllowOrdering = currentProduct.AllowOrdering, IsSellableProduct = !isProductFamily || currentProduct.Variants.Any() }; if (currentProduct.ParentProduct != null) { var parentProduct = CatalogLibrary.GetProduct(currentProduct.ParentProduct.Sku); productDetailViewModel.ParentProductUrl = UrlService.GetUrl(CatalogContext.CurrentCatalog, parentProduct); productDetailViewModel.ParentProductDisplayName = currentProduct.ParentProduct.DisplayName(); } if (currentCategory != null) { productDetailViewModel.CategoryDisplayName = currentCategory.DisplayName; productDetailViewModel.CategoryUrl = UrlService.GetUrl(CatalogContext.CurrentCatalog, CatalogContext.CurrentCategories.Append(CatalogContext.CurrentCategory).Compact(), CatalogContext.CurrentProduct); productDetailViewModel.ProductUrl = UrlService.GetUrl(CatalogContext.CurrentCatalog, CatalogContext.CurrentProduct); } var invariantFields = currentProduct.ProductProperties; var localizationContext = ObjectFactory.Instance.Resolve <ILocalizationContext>(); var fieldsForCurrentLanguage = currentProduct.GetProperties(localizationContext.CurrentCultureCode).ToList(); productDetailViewModel.ProductProperties = invariantFields.Concat(fieldsForCurrentLanguage).ToList(); var uniqueVariants = from v in currentProduct.Variants.SelectMany(p => p.ProductProperties) where v.ProductDefinitionField.DisplayOnSite group v by v.ProductDefinitionField into g select g; foreach (var vt in uniqueVariants) { var typeViewModel = productDetailViewModel.VariantTypes .Where(z => z.Id == vt.Key.ProductDefinitionFieldId) .FirstOrDefault(); if (typeViewModel == null) { typeViewModel = new VariantTypeViewModel { Id = vt.Key.ProductDefinitionFieldId, Name = vt.Key.Name, DisplayName = vt.Key.GetDisplayName() }; productDetailViewModel.VariantTypes.Add(typeViewModel); } var variants = vt.ToList(); foreach (var variant in variants) { var variantViewModel = typeViewModel.Values .Where(v => v.Value == variant.Value) .FirstOrDefault(); if (variantViewModel == null) { variantViewModel = new VariantViewModel { Value = variant.Value, TypeName = typeViewModel.Name }; if (!string.IsNullOrEmpty(variant.Product.PrimaryImageMediaId)) { var variantImageUrl = imageService.GetImage(variant.Product.PrimaryImageMediaId).Url; variantViewModel.PrimaryImageMediaUrl = UrlPath.ResolveAbsoluteUrl(variantImageUrl); } typeViewModel.Values.Add(variantViewModel); } } } productDetailViewModel.Routes.Add(RouteConstants.ADD_TO_BASKET_ROUTE_NAME, RouteConstants.ADD_TO_BASKET_ROUTE_VALUE); } return(productDetailViewModel); }
public virtual ProductDetailViewModel CreateDetailsViewModel() { ProductDetailViewModel productDetailViewModel = null; var currentProduct = SiteContext.Current.CatalogContext.CurrentProduct; if (currentProduct != null) { var imageService = UCommerce.Infrastructure.ObjectFactory.Instance.Resolve <IImageService>(); var currentCategory = SiteContext.Current.CatalogContext.CurrentCategory; string displayName = string.Empty; if (currentProduct.ParentProduct != null) { displayName = $"{currentProduct.ParentProduct.DisplayName()} "; } displayName += currentProduct.DisplayName(); var productPrice = CatalogLibrary.CalculatePrice(new List <Product>() { currentProduct }).Items.FirstOrDefault(); decimal price = 0; decimal discount = 0; if (productPrice != null) { price = productPrice.PriceExclTax; discount = productPrice.DiscountExclTax; var currentCatalog = SiteContext.Current.CatalogContext.CurrentCatalog; if (currentCatalog != null && currentCatalog.ShowPricesIncludingVAT) { price = productPrice.PriceInclTax; discount = productPrice.DiscountInclTax; } } var imageUrl = imageService.GetImage(currentProduct.PrimaryImageMediaId).Url; var absoluteImageUrl = UrlPath.ResolveAbsoluteUrl(imageUrl); productDetailViewModel = new ProductDetailViewModel() { DisplayName = displayName, Guid = currentProduct.Guid, PrimaryImageMediaUrl = absoluteImageUrl, LongDescription = currentProduct.LongDescription(), ShortDescription = currentProduct.ShortDescription(), ProductUrl = CatalogLibrary.GetNiceUrlForProduct(currentProduct, currentCategory), Price = new Money(price, SiteContext.Current.CatalogContext.CurrentPriceGroup.Currency).ToString(), Discount = new Money(discount, SiteContext.Current.CatalogContext.CurrentPriceGroup.Currency).ToString(), Sku = currentProduct.Sku, Rating = Convert.ToInt32(Math.Round(currentProduct.Rating.GetValueOrDefault())), VariantSku = currentProduct.VariantSku, IsVariant = currentProduct.IsVariant, IsProductFamily = currentProduct.ProductDefinition.IsProductFamily(), AllowOrdering = currentProduct.AllowOrdering, }; if (currentProduct.ParentProduct != null) { productDetailViewModel.ParentProductUrl = CatalogLibrary.GetNiceUrlForProduct(currentProduct.ParentProduct, currentCategory); productDetailViewModel.ParentProductDisplayName = currentProduct.ParentProduct.DisplayName(); } if (currentCategory != null) { productDetailViewModel.CategoryDisplayName = currentCategory.DisplayName(); productDetailViewModel.CategoryUrl = CatalogLibrary.GetNiceUrlForCategory(currentCategory); productDetailViewModel.ProductUrl = CatalogLibrary.GetNiceUrlForProduct(currentProduct, currentCategory); } foreach (var pv in currentProduct.Variants) { foreach (var v in pv.ProductProperties) { if (v.ProductDefinitionField != null && v.ProductDefinitionField.IsVariantProperty) { if (productDetailViewModel.VariantTypes.Any(t => t.Id == v.ProductDefinitionField.Id)) { } } } } var uniqueVariants = from v in currentProduct.Variants.SelectMany(p => p.ProductProperties) where v.ProductDefinitionField.DisplayOnSite group v by v.ProductDefinitionField into g select g; foreach (var vt in uniqueVariants) { var typeViewModel = productDetailViewModel.VariantTypes .Where(z => z.Id == vt.Key.ProductDefinitionFieldId) .FirstOrDefault(); if (typeViewModel == null) { typeViewModel = new VariantTypeViewModel { Id = vt.Key.ProductDefinitionFieldId, Name = vt.Key.Name, DisplayName = vt.Key.GetDisplayName() }; productDetailViewModel.VariantTypes.Add(typeViewModel); } var variants = vt.ToList(); foreach (var variant in variants) { var variantViewModel = typeViewModel.Values .Where(v => v.Value == variant.Value) .FirstOrDefault(); if (variantViewModel == null) { variantViewModel = new VariantViewModel { Value = variant.Value, TypeName = typeViewModel.Name }; if (!string.IsNullOrEmpty(variant.Product.PrimaryImageMediaId)) { var variantImageUrl = imageService.GetImage(variant.Product.PrimaryImageMediaId).Url; variantViewModel.PrimaryImageMediaUrl = UrlPath.ResolveAbsoluteUrl(variantImageUrl); } typeViewModel.Values.Add(variantViewModel); } } } productDetailViewModel.Routes.Add(RouteConstants.ADD_TO_BASKET_ROUTE_NAME, RouteConstants.ADD_TO_BASKET_ROUTE_VALUE); } return(productDetailViewModel); }
public async Task <ActionResult <string> > CreateStudent([FromForm] string uid) { if (uid != null) { var auth = WisClient.AuthBase64; if (string.IsNullOrEmpty(auth)) { return(NotFound()); } Debug.WriteLine("Incoming ID: " + uid); var studentRfidDto = await WisClient.GetStudentByRfidUid(uid); int?activeVariantId = VariantViewModel.ActiveVariantId; if (activeVariantId == null) { return("Variant!"); } int variantId = activeVariantId.Value; var variant = await _variantRepository.GetVariantById(variantId); var studentsDto = await WisClient.GetStudents(variant.WisCourseId); var studentDto = studentsDto?.Single(s => s.Login == studentRfidDto.Login); if (studentDto == null) { return("Not found"); } if (_studentRepository.StudentExists(studentDto.Id)) { return("Registered"); } try { var student = StudentViewModel.CreateStudent(studentDto); var studentPostDto = StudentViewModel.CreateStudentPostDto(student); await _studentRepository.InsertStudent(student); await _studentRepository.AddStudentToVariant(student.Id, variantId); await _studentRepository.SaveChanges(); if (WisClient.AutoRegister) { var registerStudentsDto = new List <StudentPostDto> { studentPostDto }; var registrationDto = VariantViewModel.CreateRegistrationDto(variant); var registeredIds = await WisClient.RegisterStudents(registerStudentsDto, registrationDto); foreach (var registeredId in registeredIds) { await _studentRepository.RegisterStudent(registeredId); await _studentRepository.SaveChanges(); } } } catch (DbUpdateConcurrencyException) { } return(studentRfidDto.Login); } return(NotFound()); }
public void Initialize(ProductEntity product, bool initializeAsMock = false) { Assert.ArgumentNotNull((object)product, nameof(product)); CatalogItem = product.Item; ProductId = product.ProductId; if (!initializeAsMock) { IsBundle = ItemTypeProvider.IsBundle(product.Item); IsCategory = ItemTypeProvider.GetItemType(CatalogItem) == Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Category; SetImages(); string str = product.Item[FieldIDs.DisplayName.ToString()]; DisplayName = string.IsNullOrEmpty(str) ? string.Empty : str; Features = CatalogItem["Features"]; CatalogName = StorefrontContext.CurrentStorefront.Catalog; Description = CatalogItem["Description"]; StockStatus = product.StockStatus; StockStatusName = product.StockStatusName; DisplayNameRender = PageContext.Current.HtmlHelper.Sitecore().Field(FieldIDs.DisplayName.ToString(), product.Item); DescriptionRender = PageContext.Current.HtmlHelper.Sitecore().Field("Description", product.Item); SetLink(); if (IsBundle) { List <BundledItemViewModel> bundledItemViewModelList = new List <BundledItemViewModel>(); NameValueCollection urlParameters = WebUtil.ParseUrlParameters(CatalogItem[Sitecore.Commerce.XA.Foundation.Common.Constants.ItemFieldNames.BundleItems]); foreach (string index in urlParameters) { BundledItemViewModel model = ModelProvider.GetModel <BundledItemViewModel>(); Item obj = Context.Database.GetItem(ID.Parse(index)); model.Initialize(obj, System.Convert.ToDecimal(urlParameters[index], CultureInfo.InvariantCulture)); bundledItemViewModelList.Add(model); } BundledItems = bundledItemViewModelList; } } else { IsCategory = false; StockStatus = product.StockStatus; StockStatusName = product.StockStatusName; Images = new List <MediaItem>(); } CurrencySymbol = CurrentStorefront.SelectedCurrency; AdjustedPrice = product.AdjustedPrice; HighestPricedVariantAdjustedPrice = product.HighestPricedVariantAdjustedPrice; ListPrice = product.ListPrice; LowestPricedVariantAdjustedPrice = product.LowestPricedVariantAdjustedPrice; LowestPricedVariantListPrice = product.LowestPricedVariantListPrice; CustomerAverageRating = product.CustomerAverageRating; if (product.Variants != null && product.Variants.Any <VariantEntity>()) { List <VariantViewModel> variantViewModelList = new List <VariantViewModel>(); foreach (VariantEntity variant in product.Variants) { VariantViewModel model = ModelProvider.GetModel <VariantViewModel>(); model.Initialize(variant); variantViewModelList.Add(model); } Variants = variantViewModelList; } if (initializeAsMock) { return; } VariantDefinitions = VariantDefinitionProvider.GetVariantDefinitions(CatalogItem); }
public ActionResult VariantInfo(VariantViewModel VariantViewModelParam) { return(View(VariantViewModelParam)); }