public async Task <IActionResult> Edit(Product product) { product.UpdatedAt = DateTime.Now; var pvm = new ProductCategoryVM { ProductName = product.ProductName, Price = product.Price, Brand = product.Brand, Model = product.Model, CompanyName = product.CompanyName, CategoryId = product.CategoryId }; if (ModelState.IsValid) { if (await _service.Update(product)) { TempData["Product"] = "Producto Actualizado"; return(RedirectToAction("Products", "Admin")); } pvm.Categories = await _categoryService.GetAll(); return(View(pvm)); } return(View(pvm)); }
public async Task <IActionResult> PutProductCategory(int id, ProductCategoryVM pcvm) { if (id != pcvm.Product_Category_ID) { return(BadRequest()); } Product_Category pc = new Product_Category(); pc.Product_Category_ID = Convert.ToInt32(pcvm.Product_Category_ID); pc.Product_Category_Name = pcvm.Product_Category_Name; db.Entry(pc).State = EntityState.Modified; await db.SaveChangesAsync(); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Product_CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> Edit(ProductCategoryVM model) { var exist = _db.ProductCategories.Any(n => (n.ProductCategoryName == model.ProductCategoryName) && n.ProductCategoryID != model.ProductCategoryID); if (exist) { ModelState.AddModelError("ProductCategoryName", "Category Name must be unique!"); } if (!ModelState.IsValid) { return(View(Request.IsAjaxRequest() ? "_Edit" : "Edit", model)); } _db.ProductCategories.UpdateCustom(model); var task = await _db.SaveChangesAsync(); if (task != 0) { return(Request.IsAjaxRequest() ? (ActionResult)Content("success") : RedirectToAction("IndexView")); } ModelState.AddModelError("", "Unable to update"); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(View(Request.IsAjaxRequest() ? "_Edit" : "Edit", model)); }
public async Task <ActionResult> Create(ProductCategoryVM model) { var exist = _db.ProductCategories.Any(n => n.ProductCategoryName == model.ProductCategoryName); if (exist) { ModelState.AddModelError("ProductCategoryName", "Category Name already exist!"); } if (!ModelState.IsValid) { return(View($"_Create", model)); } _db.ProductCategories.AddCustom(model); var task = await _db.SaveChangesAsync(); if (task != 0) { return(Content("success")); } ModelState.AddModelError("", "Unable to insert record!"); return(View($"_Create", model)); }
public ActionResult AddProduct() { ProductCategoryVM pcvm = new ProductCategoryVM(); pcvm.Product = new Product(); pcvm.Categories = cRep.GetAll(); return(View(pcvm)); }
// GET: Product public ActionResult Index() { ProductCategoryVM productCategoryVM = new ProductCategoryVM(); productCategoryVM.Products = productService.GetActive(); productCategoryVM.Categories = categoryService.GetActive(); return(View(productCategoryVM)); }
public ActionResult UpdateProduct(int id) { ProductCategoryVM pcvm = new ProductCategoryVM(); pcvm.Categories = cRep.GetAll(); pcvm.Product = pRep.Find(id); return(View(pcvm)); }
public ActionResult AddProduct() { var x = Db.Categories.ToList(); var Vm = new ProductCategoryVM { Category = x, Product = new Product() }; return(View(Vm)); }
public async Task <IActionResult> Index3() { var products = await _context.Product.ToArrayAsync(); var model = new ProductCategoryVM() { Products = products, Categorys = await GetCategoryAsync() }; return(View(model)); }
public ActionResult AddNew(ProductCategoryVM prod, HttpPostedFileBase ImgFile) { string path = Path.Combine(Server.MapPath("~/Uploads"), ImgFile.FileName); ImgFile.SaveAs(path); prod.Product.image = ImgFile.FileName; //Session["img"] = prod.Product.image; if (prod.Product.id == 0) { Db.Products.Add(prod.Product); } else { var prodInDb = Db.Products.SingleOrDefault(c => c.id == prod.Product.id); prodInDb.name = prod.Product.name; prodInDb.image = prod.Product.image; prodInDb.description = prod.Product.description; prodInDb.price = prod.Product.price; prodInDb.category_id = prod.Product.category_id; } if (prod.Product.id == 0) { if (prod.Product.category_id == 1) { var x = Db.Categories.SingleOrDefault(c => c.id == 1); x.number_of_products = prod.Product.category.number_of_products + 1; x.name = prod.Product.category.name; Db.Entry(x).State = EntityState.Modified; } else if (prod.Product.category_id == 2) { var x = Db.Categories.SingleOrDefault(c => c.id == 2); x.number_of_products = prod.Product.category.number_of_products + 1; x.name = prod.Product.category.name; Db.Entry(x).State = EntityState.Modified; } else if (prod.Product.category_id == 3) { var x = Db.Categories.SingleOrDefault(c => c.id == 3); x.number_of_products = prod.Product.category.number_of_products + 1; x.name = prod.Product.category.name; Db.Entry(x).State = EntityState.Modified; } } Db.SaveChanges(); return(RedirectToAction("ListOfProducts", "Products")); }
// GET: ProductCategories/Create public IActionResult Create(int parentId) { var parent = _context.ProductCategory.Find(parentId); if (parent == null) { NotFound($"Няма такава родителска категория ID#{parentId}"); } var model = new ProductCategoryVM(parent); return(View(model)); }
public ActionResult UpdateProduct(ProductCategoryVM model) { if (ModelState.IsValid) { pRep.Update(model.Product); ViewBag.Status = 1; return(RedirectToAction("")); } else { ViewBag.Status = 2; return(View()); } }
public async Task <ActionResult <Product_Category> > PostProductCategory([FromBody] ProductCategoryVM pcvm) { Product_Category pc = new Product_Category(); //pc.Product_Category_ID = Convert.ToInt32(pcvm.Product_Category_ID); pc.Product_Category_Name = pcvm.Product_Category_Name; db.Product_Category.Add(pc); //db.Entry(pc).State = EntityState.Modified; await db.SaveChangesAsync(); return(Ok()); }
public ActionResult AddProduct(ProductCategoryVM vmModel, HttpPostedFileBase image) { if (ModelState.IsValid) { vmModel.Product.ImagePath = ImageUploader.UploadImage("~/Pictures/", image); pRep.Add(vmModel.Product); ViewBag.Status = 1; return(RedirectToAction("AddProduct")); } else { ViewBag.Status = 2; return(View()); } }
public ICollection<ProductCategoryVM> GetSome(int n) { var plist = Context.ProductCategory.Take(n).OrderByDescending(c => c.Name).ToList(); List<ProductCategoryVM> list = new List<ProductCategoryVM>(); foreach (var t in plist) { ProductCategoryVM b = new ProductCategoryVM(); b.Id = t.Id; b.Name = t.Name; b.BrandId = t.BrandId; list.Add(b); } return list.ToList(); }
public ActionResult Edit(int id) { var prod = Db.Products.SingleOrDefault(c => c.id == id); if (prod == null) { return(HttpNotFound()); } var vm = new ProductCategoryVM { Product = prod, Category = Db.Categories.ToList() }; return(View("Edit", vm)); }
public async Task <IActionResult> Filter2(ProductCategoryVM viewModel) { var products = string.IsNullOrWhiteSpace(viewModel.Name) ? _context.Product : _context.Product.Where(m => m.Name.StartsWith(viewModel.Name)); products = viewModel.Category == null ? products : products.Where(m => m.Category == viewModel.Category); var model = new ProductCategoryVM { Products = products, Categorys = await GetCategoryAsync() }; return(View(nameof(Index3), model)); }
public async Task <IActionResult> Edit(Guid id) { var product = await _service.GetById(id); if (product != null) { var pvm = new ProductCategoryVM { Id = product.Id, ProductName = product.ProductName, Price = product.Price, Brand = product.Brand, Model = product.Model, Quantity = product.Quantity, CompanyName = product.CompanyName, CategoryId = product.CategoryId, Categories = await _categoryService.GetAll() }; return(View(pvm)); } return(RedirectToAction("Products", "Admin")); }
public IActionResult Pdf(Product product) { ProductCategoryVM productCategoryVM = new ProductCategoryVM(); productCategoryVM.Products = productService.GetActive(); ProductReport productReport = new ProductReport(_hostingEnvironment); return(File(productReport.Report(productCategoryVM.Products), "application/pdf")); //HtmlToPdfConverter converter = new HtmlToPdfConverter(); //WebKitConverterSettings settings = new WebKitConverterSettings(); //settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows"); //converter.ConverterSettings = settings; //PdfDocument document = converter.Convert("http://localhost:44347/ManagerPanel/Product/product"); //MemoryStream memory = new MemoryStream(); //document.Save(memory); //return File(memory.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Output.pdf"); }
public async Task <IActionResult> Create(Product product) { product.CreatedAt = DateTime.Now; var pvm = new ProductCategoryVM { ProductName = product.ProductName, Price = product.Price, Brand = product.Brand, Model = product.Model, CompanyName = product.CompanyName, CategoryId = product.CategoryId, Categories = await _categoryService.GetAll() }; if (ModelState.IsValid) { if (await _service.Add(product)) { return(RedirectToAction("Products", "Admin")); } return(View(pvm)); } return(View(pvm)); }