public ActionResult CreatingInvoice(int Id = -1) { int id = int.Parse(User.Claims.ToList()[1].Value); var enter = _context.Enterprises.Find(id); var NameCategory = "baseCategory." + enter.Name; Category cat1 = null; if (Id != -1) { cat1 = _context.Categories.Find(Id); if (NameCategory != cat1.Name) { NameCategory = cat1.Name; } else { cat1 = null; } } CartClassForInvoice cartClassForInvoice = new CartClassForInvoice("Product_in_InomingInvoice", _context, HttpContext); var e = cartClassForInvoice.GetCart().Lines; ViewBag.Products = cartClassForInvoice.GetCart().Lines; ViewBag.IncomingInvoice = new IncomingInvoice(); ViewData["Storages"] = new SelectList(_context.Storages.Where(p => p.EnterpriseId == id), "Id", "Name"); var categories = _context.Categories.Where(p => p.EnterpriseId == id && p.ParentCategory.Name == NameCategory).ToList(); var products = _context.Products.Where(p => p.ParCategory.EnterpriseId == id && p.ParCategory.Name == NameCategory).ToList(); ViewBag.categ = categories; ViewBag.prod = products; return(View()); }
public RedirectToActionResult AddToCart(int id, string returnUrl) { CartClassForInvoice cartClassForInvoice = new CartClassForInvoice("Product_in_InomingInvoice", _context, HttpContext); cartClassForInvoice.AddToCart(id, returnUrl); return(RedirectToAction("CreatingInvoice")); }
// GET: IncomingInvoices public async Task <IActionResult> Index(int Id = -1) { int id = int.Parse(User.Claims.ToList()[1].Value); var enter = _context.Enterprises.Find(id); var NameCategory = "baseCategory." + enter.Name; Category cat1 = null; if (Id != -1) { cat1 = _context.Categories.Find(Id); if (NameCategory != cat1.Name) { NameCategory = cat1.Name; } else { cat1 = null; } } var productContext = _context.IncomingInvoices.Where(p => p.Storage.EnterpriseId == id); ViewBag.IncomingInvoice = new IncomingInvoice(); /* var e = new List<Product>(); * e.Add(new Product { Name = "sadsad" });*/ CartClassForInvoice cartClassForInvoice = new CartClassForInvoice("Product_in_InomingInvoice", _context, HttpContext); var e = cartClassForInvoice.GetCart().Lines; ViewBag.Products = cartClassForInvoice.GetCart().Lines; var categories = _context.Categories.Where(p => p.EnterpriseId == id && p.ParentCategory.Name == NameCategory).ToList(); var products = _context.Products.Where(p => p.ParCategory.EnterpriseId == id && p.ParCategory.Name == NameCategory).ToList(); ViewBag.categ = categories; ViewBag.prod = products; ViewData["Storages"] = new SelectList(_context.Storages.Where(p => p.EnterpriseId == id), "Id", "Name"); if (cat1 != null) { ViewBag.ParentCatName = cat1.Name; ViewBag.ParentCatId = _context.Categories.First(p => p.Name == cat1.ParentCategory.Name).Id; } return(View(await productContext.ToListAsync())); }
public RedirectToActionResult CreateIncomingInvoice([Bind("Id,Date,StorageId")] IncomingInvoice incomingInvoice) { CartClassForInvoice cartClassForInvoice = new CartClassForInvoice("Product_in_InomingInvoice", _context, HttpContext); incomingInvoice.Date = DateTime.Now; incomingInvoice.UserId = _context.Users.FirstOrDefault(s => s.Login == User.Identity.Name).Id; _context.IncomingInvoices.Add(incomingInvoice); _context.SaveChanges(); var e = cartClassForInvoice.GetCart().Lines; foreach (var el in e) { el.InvoiceId = incomingInvoice.Id; Invoice_Product newInvo = new Invoice_Product { InvoiceId = incomingInvoice.Id, ProductId = el.ProductId, Quantity = el.Quantity }; _context.Invoice_Products.Add(newInvo); } _context.SaveChanges(); cartClassForInvoice.Clear(); return(RedirectToAction("Index")); }