public VMProducts ProductsModel() { VMProducts vm = new VMProducts(); vm.Products = new List <CommonProduct>(); foreach (var p in dbContext.Products.Include("Size").GroupBy(x => new { x.Size.ID, x.Size.Name, x.Size.Width, x.Size.Height })) { CommonProduct c = new CommonProduct(); c.SizeID = p.Key.ID; c.SizeName = p.Key.Name; c.Width = (int)p.Key.Width; c.Height = (int)p.Key.Height; c.Colors = new List <string>(); c.Img = dbContext.Products.Where(y => y.SizeID == p.Key.ID).FirstOrDefault().Img; foreach (var s in dbContext.Products.Include("Size").Where(y => y.Size.Name == c.SizeName)) { c.Colors.Add(s.Color); foreach (var g in s.Size.Games) { c.Games = new List <string>(); c.Games.Add(g.Name); } } vm.Products.Add(c); } return(vm); }
/// <summary> /// Generates a Cookie to keep information abuout a Product. /// </summary> /// <param name="objProduct"></param> private void KeepTrackOfHitCounter(CommonProduct objProduct) { HttpContext context = HttpContext.Current; string key = objProduct.CategoryID.ToString() + "." + objProduct.ProductSellerDetailID.ToString(); context.Response.Cookies[key][key] = key; context.Response.Cookies[key].Expires = DateTime.Now.AddDays(_ProductCookiePersistDay); }
/// <summary> /// Increments a products HitCounterField. /// USP: USP_Common_BS_Product_HitCounter /// </summary> /// <param name="objProduct"></param> /// <returns></returns> public int IncrementProductCounter(CommonProduct objProduct) { Hashtable ht = new Hashtable(); ht.Add("@CategoryID", objProduct.CategoryID); ht.Add("@ProductSellerDetailID", objProduct.ProductSellerDetailID); try { return(this.ExecuteNonQueryStoredProcedure("USP_Common_BS_Product_HitCounter", ht)); } catch { throw; } }
/// <summary> /// Increments a product HitCounter once for a specific day. /// </summary> /// <param name="_CategoryID"></param> /// <param name="_ProductSellerDetailID"></param> private void IncrementProductCounter(int _CategoryID, int _ProductSellerDetailID) { try { CommonProduct objProduct = new CommonProduct(); objProduct.CategoryID = _CategoryID; objProduct.ProductSellerDetailID = _ProductSellerDetailID; ProductHandler handler = new ProductHandler(); handler.IncrementProductCounter(objProduct); } catch (Exception ex) { lblSystemMessage.Text = ex.Message; } }
/// <summary> /// Checks if the products hitcounter field is already updated by checking the cookies. /// Returns true if already Updated, false otherwise /// </summary> /// <returns></returns> private bool IsAlreadyUpdated(CommonProduct objProduct) { bool _Result = false; HttpContext context = HttpContext.Current; string key = objProduct.CategoryID.ToString() + "." + objProduct.ProductSellerDetailID.ToString(); string cookieKey = ""; //object o = context.Request.Cookies["PRODUCT_COUNTER"]; //object ob = context.Request.Cookies["PRODUCT_COUNTER"][key]; if (context.Request.Cookies[key] != null && context.Request.Cookies[key][key] != null) { cookieKey = context.Request.Cookies[key][key].ToString(); if (key == cookieKey) { _Result = true; } } return(_Result); }
/// <summary> /// Increments a products HitCounterField. /// </summary> /// <param name="objProduct"></param> /// <returns></returns> public bool IncrementProductCounter(CommonProduct objProduct) { int _ActionResult = -1; if (!this.IsAlreadyUpdated(objProduct)) { try { using (BC_Product product = new BC_Product()) { _ActionResult = product.IncrementProductCounter(objProduct); if (_ActionResult > 0) { this.KeepTrackOfHitCounter(objProduct); } } } catch (Exception ex) { throw; } } return(_ActionResult > 0 ? true : false); }
public async Task <IActionResult> Order() { if (User.Identity.Name != null && User.Identity.IsAuthenticated) { if (_context.CartItems.Any()) { List <CartItem> cartItems = new List <CartItem>(); List <CartItem> cartItemsDb = await _context.CartItems.ToListAsync(); //ziskanie z kosika foreach (var item in cartItemsDb) { var cartItem = new CartItem { CartProduct = _context.Products.Where(p => p.ID == item.ProductID).FirstOrDefault(), ProductID = _context.Products.Where(p => p.ID == item.ProductID).FirstOrDefault().ID, }; cartItems.Add(cartItem); _context.CartItems.Remove(item); } await _context.SaveChangesAsync(); // pridanie do comon items //pre kazdy produkt v kosiku foreach (var cartItm in cartItems) { //pripiseme kazdu polozku z kosiku ako common foreach (var item in cartItems) { //ochrana pred pridanim sameho seba ako common if (cartItm != item) { CommonProduct commonProduct = new CommonProduct { ProductID = cartItm.ProductID, CommonProductID = item.CartProduct.ID }; if (!_context.CommonProductsDbSet.Any(cp => cp.ProductID == cartItm.ProductID && cp.CommonProductID == item.CartProduct.ID)) { _context.CommonProductsDbSet.Add(commonProduct); } await _context.SaveChangesAsync(); } } } await _context.SaveChangesAsync(); //var pp = _context; //vytvorenie objednavky Order order; if (!_context.Order.Any()) { order = new Order { OrderNumber = "0", UserName = User.Identity.Name, OrderItems = new List <OrderItem>() }; } else { order = new Order { OrderNumber = (UInt32.Parse(_context.Order.Last().OrderNumber) + 1).ToString(), UserName = User.Identity.Name, OrderItems = new List <OrderItem>() }; } _context.Order.Add(order); await _context.SaveChangesAsync(); //vytvorenie orderItems IList <OrderItem> orderItemsList = new List <OrderItem>(); foreach (var item in cartItems) { OrderItem orderItem = new OrderItem { Order = _context.Order.Where(o => o.ID == order.ID).FirstOrDefault(), Amount = 1, Price = item.CartProduct.Price, ProductID = item.CartProduct.ID, OrderID = _context.Order.Where(o => o.ID == order.ID).FirstOrDefault().ID, Product = item.CartProduct, }; orderItemsList.Add(orderItem); } //pridanie orderItems do objednavky Order editingOrder = _context.Order.Where(o => o.ID == order.ID).FirstOrDefault(); editingOrder.OrderItems = orderItemsList; await _context.SaveChangesAsync(); } } return(View(nameof(Index))); }
static void Main(string[] args) { int Option = ShowMenu(); /*Instanciando os objetos para que possam estar acessíveis*/ Customer Customer = new Customer(); Product product = new CommonProduct(); Order order = new Order(); List <Product> ListProduct = new List <Product>(); List <OrderItem> ListOrdemItem = new List <OrderItem>(); while (Option != 9) { if (Option == 1) { string CustomerName, CustomerEmail; DateTime CustomerBirthDate; Console.Write("Customer name >>> "); CustomerName = Console.ReadLine(); Console.Write("Customer mail >>> "); CustomerEmail = Console.ReadLine(); Console.Write("Customer birth >>> "); CustomerBirthDate = DateTime.Parse(Console.ReadLine()); Customer = new Customer(0, CustomerName, CustomerEmail, CustomerBirthDate); } if (Option == 2) { /*Pode-se registrar 3 tipos de produtos: comum, usados (que terão data de fabricação) * e importados( que terão taxa alfandegária de 110% sobre o valor do imposto acrescido no seu preço) */ string ProductName; double ProductPrice; int QtdeProduct; Console.Write("How many products will be registered ? >>> "); QtdeProduct = int.Parse(Console.ReadLine()); for (int i = 0; i < QtdeProduct; i++) { try { Console.Write("Product name >>> "); ProductName = Console.ReadLine(); Console.Write("Price >>> "); ProductPrice = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.Write("Commom, used or imported (C/U/I) >>> "); char opt = char.Parse(Console.ReadLine()); if (opt == 'C' || opt == 'c') { product = new CommonProduct(i, ProductName, ProductPrice); ListProduct.Add(product); } if (opt == 'U' || opt == 'u') { Console.Write("Manufacture date >>> "); DateTime date = DateTime.Parse(Console.ReadLine()); product = new UsedProduct(i, ProductName, ProductPrice, date); ListProduct.Add(product); } if (opt == 'I' || opt == 'i') { Console.Write("Customs fee>>> "); double FeeC = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); product = new ImportedProduct(i, ProductName, ProductPrice, FeeC); ListProduct.Add(product); } } catch (FormatException f) { Console.WriteLine("Format is not allowed!" + f); } } } if (Option == 3) { int XProd, XProdQtde = 0; Console.Write("\nCustomer name >>> " + Customer.Nome); Console.Write("\nCustomer e-mail >>> " + Customer.Email); Console.Write("\nCustomer BirthDate>>> " + Customer.BirthDate); order = new Order(0, DateTime.Now, OrderStatus.PendingPayment, Customer); if (ListProduct.Count == 0) { Console.WriteLine("\nOOH No, you haven't products on the list!!"); } else { int flag = 0; while (flag == 0) { try { Console.WriteLine("\nChange product for add on the order >>> "); foreach (Product item in ListProduct) { Console.WriteLine(item.Id + " - " + item.Name); } XProd = int.Parse(Console.ReadLine()); Console.WriteLine("\nQuantity >>> "); XProdQtde = int.Parse(Console.ReadLine()); OrderItem orderItem = new OrderItem(0, ListProduct.ElementAt(XProd), XProdQtde, ListProduct.ElementAt(XProd).Price); order.AddItem(orderItem); Console.WriteLine("\n0 for add more products on the order "); flag = int.Parse(Console.ReadLine()); } catch (FormatException f) { Console.WriteLine("Format is not allowed: " + f.Message); } } } } if (Option == 4) { Console.Write("\nCustomer name >>> " + Customer.Nome); Console.Write("\nCustomer e-mail >>> " + Customer.Email); Console.Write("\nCustomer BirthDate>>> " + Customer.BirthDate); Console.Write("\nOrder>>> " + order.id); Console.Write("\nMoment>>> " + order.Moment); Console.Write("\nStatus>>> " + order.Status); Console.WriteLine(""); Console.WriteLine("\n******** ITEMS ********"); Console.WriteLine(); Console.WriteLine("_________________________________________________"); Console.WriteLine("| |"); Console.WriteLine("| Product | Quantity | Price | Total Item|"); Console.WriteLine("|________________________________________________|"); foreach (OrderItem item in order.Items) { Console.WriteLine("| " + item.Product.Name + " | " + item.Quantity + " | R$ " + item.Price + " | R$ " + item.SubTotal() + " |"); } Console.WriteLine("|_________________________________________________|"); Console.WriteLine("Total>>> " + order.Total()); Console.WriteLine(""); Console.WriteLine("**************************"); } if (Option == 5) { Console.WriteLine(); Console.WriteLine(" ********* PRICE TAGS ************"); foreach (Product item in ListProduct) { Console.WriteLine(item.PriceTag()); } } Option = ShowMenu(); } }