public async Task <IActionResult> AddProduct(ViewModelProduct model) { if (ModelState.IsValid) { var path = Path.Combine(_environment.ContentRootPath + $"/wwwroot/images/{model.CategoryId}"); var photoPath = $"images/{model.CategoryId}/{model.File.FileName}"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } await UploadService.Upload(path, model.File.FileName, model.File); #region временный var categoryId = await _db.Subcategories.FirstOrDefaultAsync(s => s.Id == model.SubcategoryId); model.CategoryId = categoryId.CategoryId; #endregion model.ImgPath = photoPath; model.AuthorId = UserManager.GetUserId(User); var product = new Product(model); await _db.Products.AddAsync(product); await _db.SaveChangesAsync(); return(RedirectToAction("ControlPanel", "Users")); } ViewBag.Subcaegory = await _db.Subcategories.ToListAsync(); return(View(model)); }
public async Task <ActionResult> Add(ViewModelProduct productViewModel) { try { if (ModelState.IsValid) { string nameFile = "default.jpg"; if (productViewModel.UploadedFile != null) { nameFile = $"{new Random().Next(100, 999)}_{Regex.Replace(productViewModel.Name.Trim(), @"\s", "")}.{Path.GetExtension(productViewModel.UploadedFile.FileName)}"; string path = Path.Combine(Server.MapPath("~/Content/images/products"), nameFile); productViewModel.UploadedFile.SaveAs(path); } productViewModel.Image = nameFile; var product = Mapper.Map <ViewModelProduct, Product>(productViewModel); int IdProduct = await CommAPIProduct.AddAsync(product); return(RedirectToAction("List")); } else { return(await Add()); } } catch (Exception ex) { return(await Add()); } }
public void InsertOrUpdate(ViewModelProduct vproduct) { try { _iProductRepository.InsertOrUpdate(Mapper.Map <ViewModelProduct, Product>(vproduct)); _iProductRepository.Save(); } catch (Exception e) { } }
public IActionResult Details(int id) { List <ViewModelProduct> data = ViewModelProduct.GetData(); var result = from item in data where item.Id == id select item; if (result.Count() == 0) { return(NotFound("Продукт по Id = " + id.ToString() + " - не найден.")); } return(View(result.First())); }
public ActionResult Index() { UnitOfWork unitOfWork = new UnitOfWork(); List <Product> products = unitOfWork.Product.GetAll().ToList(); ViewModelProduct viewModelProduct = new ViewModelProduct(); viewModelProduct.Products = products; return(View(viewModelProduct)); }
public Product(ViewModelProduct model) { Name = model.Name; TotalDelivered = model.TotalDelivered; Price = model.Price; Description = model.Description; Specification = model.Specification; Brand = model.Brand; SubcategoryId = model.SubcategoryId; CategoryId = model.CategoryId; ImgPath = model.ImgPath; }
public ActionResult Delete(int id, ViewModelProduct collection) { try { // TODO: Add delete logic here var result = _iProductService.Delete(collection); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, ViewModelProduct collection) { try { // TODO: Add update logic here _iProductService.InsertOrUpdate(collection); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(ViewModelProduct vproduct) { try { // TODO: Add insert logic here _iProductService.AddProduct(vproduct); return(RedirectToAction("Index")); } catch { return(View()); } }
public ViewModelProduct Delete(ViewModelProduct vproduct) { try { _iProductRepository.Delete(vproduct.Id); _iProductRepository.Save(); return(vproduct); } catch (Exception e) { return(null); } }
public async Task <ActionResult> Add() { ViewBag.Title = ResourceGlobal.Title_Register_Product; ViewBag.ButtonCancel = ResourceGlobal.Button_Cancel; ViewBag.ButtonSave = ResourceGlobal.Button_Save; List <Category> categories = await CommAPICategory.GetAllAsync(); var viewModelProduct = new ViewModelProduct(); var categoryViewModel = Mapper.Map <List <Category>, List <ViewModelCategory> >(categories); viewModelProduct.CategoriesSelect = categoryViewModel; return(View(viewModelProduct)); }
public ActionResult Category(int id) { if (id > 10 || id < 1) { return(HttpNotFound()); } UnitOfWork unitOfWork = new UnitOfWork(); List <Product> products = unitOfWork.Product.Find(x => x.CategoryId == id).ToList(); ViewModelProduct viewModelProduct = new ViewModelProduct(); viewModelProduct.Products = products; return(View(viewModelProduct)); }
public ActionResult add(ViewModelProduct vproduct) { _iProductService.AddProduct(vproduct); return(RedirectToAction("Index")); }
public EditCurrentProduct(ViewModelProduct viewProduct) { InitializeComponent(); this.DataContext = viewProduct; }
public void AddProduct(ViewModelProduct vproduct) { _iProductRepository.InsertOrUpdate(Mapper.Map <ViewModelProduct, Product>(vproduct)); _iProductRepository.Save(); }
public IActionResult List() { List <ViewModelProduct> data = ViewModelProduct.GetData(); return(View(data)); }
public CreateProductWindow(ViewModelProduct viewProduct) { InitializeComponent(); this.DataContext = viewProduct; }