public ActionResult ViewProductModal(int id, int supplierNumber, int quantity) { string userId = User.Identity.GetUserId(); ShoppingCart cart = GetCartFromSession(userId); if (User.Identity.Name != null) { if (User.Identity.Name == ConfigurationManager.AppSettings["developerIdentity"]) { } else { AuditUser.LogAudit(32, "Hit", userId); } } else { AuditUser.LogAudit(32, "Hit"); } ViewProductViewModel model = new ViewProductViewModel(id, supplierNumber, quantity, cart.Order.OrderNumber); if (model == null) { return(RedirectToAction("Departments", "Product")); } return(PartialView("_ViewProductModal", model)); }
public ActionResult ViewProduct(int id, string urlRedirect) { try { ViewBag.Message = urlRedirect; ViewProductViewModel model = new ViewProductViewModel(); ViewBag.Message = urlRedirect; if (Product.IsPrescriptionGlasses(id)) { PrescriptionGlasses p = new PrescriptionGlasses(id); model.Id = p.ProductId.ToString(); model.Name = p.Name; model.Price = decimal.Round(p.Price).ToString(); model.PrimaryImage = p.PrimaryImage; model.Lens = p.Lens.LensName; model.Description = p.ProductDescription; model.DiscountedPrice = decimal.Round(p.GetDiscountedPrice()).ToString(); if (p.Quantity == 0) { model.Status = "Out of Stock"; } else { model.Status = p.Quantity + " Item(s) available"; } model.Frame = p.Frame.FrameName; model.FrameColor = p.FrameColor; model.Images = p.Images; model.IsSunglasses = false; } else if (Product.IsSunglasses(id)) { Sunglasses s = new Sunglasses(id); model.Id = s.ProductId.ToString(); model.Name = s.Name; model.Price = decimal.Round(s.Price).ToString(); model.PrimaryImage = s.PrimaryImage; model.LensColor = s.LensColor; model.Description = s.ProductDescription; model.DiscountedPrice = decimal.Round(s.GetDiscountedPrice()).ToString(); if (s.Quantity == 0) { model.Status = "Out of Stock"; } else { model.Status = s.Quantity + " Item(s) remaining"; } model.FrameColor = s.FrameColor; model.Images = s.Images; model.IsSunglasses = true; } return(View(model)); } catch (Exception ex) { HandleErrorInfo error = new HandleErrorInfo(ex, "Home", "ViewProduct"); return(RedirectToAction("Index", "Error", new { model = error })); } }
public ActionResult ViewProduct(int id) { ViewProductViewModel model = new ViewProductViewModel(); model.Product = products.FindById(id); model.PeopleReadyToBuy = carts.ProductCountInCarts(model.Product); model.RelatedProducts = model.Product.Category.Products.Where(x => x.Id != id).Take(3); return(View(model)); }
public IActionResult AddInCategory(ViewProductViewModel viewModel, int ProductId) { System.Console.WriteLine("******************************"); viewModel.Association.ProductId = ProductId; dbContext.Add(viewModel.Association); dbContext.SaveChanges(); System.Console.WriteLine("################################"); return(RedirectToAction("Product", new{ ProductId = ProductId })); }
public IActionResult ViewProduct(int id) { ShoppingManager mgr = new ShoppingManager(_connectionString); ViewProductViewModel vm = new ViewProductViewModel { Categories = mgr.GetAllCategories(), Product = mgr.GetProduct(id) }; return(View(vm)); }
public IActionResult Product(int ProductId) { ViewProductViewModel viewModel = new ViewProductViewModel(); viewModel.currentProduct = dbContext.Products .Include(p => p.Associations) .ThenInclude(pc => pc.Category) .FirstOrDefault(p => p.ProductId == ProductId); viewModel.CategoryList = dbContext.Categories .Include(c => c.Associations) .ThenInclude(pc => pc.Product) .Where(c => !viewModel.currentProduct.Associations.Select(pc => pc.Category).Contains(c)) .ToList(); return(View("Product", viewModel)); }
public IActionResult ViewProducts(int Id) { var viewModel = new ViewProductViewModel(); viewModel.Products = _dbContext.Product.Where(p => p.ProductCategory.Id == Id) .Select(prod => new ViewProductViewModel { Id = prod.Id, Description = prod.Description, Name = prod.Name, Price = prod.Price, ProductCategory = prod.ProductCategory }).ToList(); return(View(viewModel)); }
public ActionResult ViewProduct(int id, int supplierNumber, int quantity) { string userId = User.Identity.GetUserId(); ShoppingCart cart = GetCartFromSession(userId); ViewProductViewModel model = new ViewProductViewModel(id, supplierNumber, quantity, cart.Order.OrderNumber); if (model == null) { return(RedirectToAction("Departments", "Product")); } model.Reviews = ProductReviewsCollection.GetReviewsOnly(id, supplierNumber, 0); return(View("ViewProduct", model)); }
public async Task <IActionResult> ViewProduct(int productId) { ViewProductViewModel vm = new ViewProductViewModel(); vm.Feedbacks = new List <FeedbackDetails>(); var product = await _context.Products.SingleOrDefaultAsync(pd => pd.ProductID == productId); if (product != null) { var inventory = await _context.Inventories.SingleOrDefaultAsync(iv => iv.ProductID == productId); vm.ProductDescription = product.ProductDescription; vm.ProductName = product.ProductName; vm.ProductID = product.ProductID; vm.ProductImage = product.ProductImage; vm.StocksLeft = inventory.Quantity; vm.Price = product.Price; vm.Critical = inventory.CriticalLevel; var feedbacks = await _context.Feedbacks.Where(f => f.ProductID == productId).ToListAsync(); if (feedbacks != null) { foreach (var fb in feedbacks) { var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == fb.UserID); if (user != null) { vm.Feedbacks.Add(new FeedbackDetails { Rating = fb.Rating, FeedbackMessage = fb.FeedbackMessage, FeedbackID = fb.FeedbackID, User = user, DateCreated = fb.DateCreated, IsArchived = fb.IsArchived }); } } } return(View(vm)); } return(NotFound()); }
private async Task PinSecondaryTile(object sender, ViewProductViewModel vm) { try { //Prepare the Tile metadata Uri smallLogo = new Uri("ms-appx://" + vm.ProductDetails.ImagePath); string tileActivationArguments = vm.ProductDetails.Id; string subTitle = vm.ProductDetails.Name; //Create the Secondary Tile and set the VisualElements options. SecondaryTile secondaryTile = new SecondaryTile(vm.ProductDetails.Id, subTitle, tileActivationArguments, smallLogo, TileSize.Square150x150); secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true; secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark; //Accent color for tile which will work if Foreground Text is either Black or White. secondaryTile.VisualElements.BackgroundColor = Color.FromArgb(255, 27, 161, 226); //Attempt to Pin the Tile bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Above); //Set the Pinned State from the returned status (nb: don't wait until system can find the tile as it may not happen until a few MS later) vm.SetPinnedState(isPinned); //Notify the User of the Pinned Status. if (isPinned) { MessageDialog dialog = new MessageDialog("Product " + vm.ProductDetails.Name + " successfully pinned."); await dialog.ShowAsync(); } else { MessageDialog dialog = new MessageDialog("Product " + vm.ProductDetails.Name + " not pinned."); await dialog.ShowAsync(); } } catch (Exception e) { MessageDialog dialog = new MessageDialog("There was an error pinning this tile. \n\n Message : " + (e.Message ?? "(Error Details Unavailable)"), "Error Pinning Tile"); await dialog.ShowAsync(); } }
public async Task <IActionResult> View(int id) { var productQuery = from product0 in StoreContext.Products.AsNoTracking() .Include(product0 => product0.ProductImages) where product0.Id == id select product0; var product = await productQuery.FirstOrDefaultAsync(); if (productQuery == null) { return(NotFound()); } var viewModel = new ViewProductViewModel { Product = product }; return(View(viewModel)); }
/// <summary> /// This method unpins the existing secondary tile. /// The user is shown a message informing whether the tile is unpinned successfully /// </summary> /// <param name="sender">The sender.</param> /// <param name="vm">The Current Product View Model.</param> /// <returns></returns> private async Task UnpinSecondaryTile(object sender, ViewProductViewModel vm) { try { if (SecondaryTile.Exists(vm.ProductDetails.Id)) { SecondaryTile secondaryTile = new SecondaryTile(vm.ProductDetails.Id); //nb: should always return true as we checked with Exists() if (secondaryTile != null) { bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Above); vm.SetPinnedState(!isUnpinned); if (isUnpinned) { MessageDialog dialog = new MessageDialog("Product " + vm.ProductDetails.Name + " successfully unpinned."); await dialog.ShowAsync(); } else { MessageDialog dialog = new MessageDialog("Product " + vm.ProductDetails.Name + " not unpinned."); await dialog.ShowAsync(); } } } else { MessageDialog dialog = new MessageDialog("The tile for Product " + vm.ProductDetails.Name + " was not located."); await dialog.ShowAsync(); } } catch (Exception e) { MessageDialog dialog = new MessageDialog("There was an error unpinning this tile. \n\n Message : " + (e.Message ?? "(Error Details Unavailable)"), "Error Unpinning Tile"); await dialog.ShowAsync(); } }
public ActionResult AddToCart(ViewProductViewModel viewModel) { // Validate if (viewModel.ProductNumber == 0 || viewModel.SupplierNumber == 0) { TempData["errorMessage"] = "Error: We could not add the item to the cart."; return(JavaScript("window.location = window.location.href;")); } if (ModelState.IsValid) { string userId = User.Identity.GetUserId(); bool anonymousUser = (userId == null); ShoppingCart cart = GetCartFromSession(userId); if (cart.Order.OrderStatus == "Locked") { TempData["errorMessage"] = "Your cart is locked because you are in the process of checking out. Open your cart to complete or cancel the checkout process."; if (Request.IsAjaxRequest()) { return(JavaScript("window.location = window.location.href;")); } else { return(RedirectToAction("Cart", "ShoppingCart")); } } // CheckQuantity if (viewModel.CustodianQuantityOnHand < viewModel.Quantity) { viewModel.SetInstances(viewModel.ProductNumber, viewModel.SupplierNumber); if (Request.IsAjaxRequest()) { return(PartialView("_ViewProductModal", viewModel)); } else { viewModel.Reviews = ProductReviewsCollection.GetReviewsOnly(viewModel.ProductNumber, viewModel.SupplierNumber, 0); return(View("ViewProduct", viewModel)); } } FreeMarketObject result; result = cart.AddItemFromProduct(viewModel.ProductNumber, viewModel.SupplierNumber, viewModel.Quantity, viewModel.CustodianNumber, viewModel.SelectedPackageType); if (result.Result == FreeMarketResult.Success) { // New item added if (!string.IsNullOrEmpty(result.Message)) { TempData["message"] = result.Message; } else if (!string.IsNullOrEmpty(result.Message)) { TempData["errorMessage"] = result.Message; } } if (Request.IsAjaxRequest()) { return(JavaScript("window.location = window.location.href;")); } else { viewModel.Reviews = ProductReviewsCollection.GetReviewsOnly(viewModel.ProductNumber, viewModel.SupplierNumber, 0); return(RedirectToAction("Cart", "ShoppingCart")); } } // Validation Error else { // Prepare viewModel.SetInstances(viewModel.ProductNumber, viewModel.SupplierNumber); if (Request.IsAjaxRequest()) { return(PartialView("_ViewProductModal", viewModel)); } else { viewModel.Reviews = ProductReviewsCollection.GetReviewsOnly(viewModel.ProductNumber, viewModel.SupplierNumber, 0); return(View("ViewProduct", viewModel)); } } }