public async Task <ActionResult> Create(ProductCreateVM vm) { if (ModelState.IsValid) { var product = vm.ToProduct(); if (vm.SuppliersSelected != null && vm.SuppliersSelected.Length > 0) { var suppliers = await GetSupplierQuery() .Where(s => vm.SuppliersSelected.Contains(s.Id)) .ToListAsync(); foreach (var item in suppliers) { if (!product.Suppliers.Contains(item)) { product.Suppliers.Add(item); } } } DataContext.Products.Add(product); await DataContext.SaveChangesAsync(this); return(RedirectToAction("Create", "PurchaseOrders", new { productId = product.Id })); } await SetProductCategorySelectListAsync(vm); await SetCurrencySelectLists(vm); return(View(vm)); }
public async Task <ActionResult> Edit(int id) { ProductDTO product = await _productManager.GetAsync(id); if (product == null || product.Id != id) { return(NotFound()); } var editModel = new ProductCreateVM { Product = new ProductVM { Id = product.Id, CountryId = product.CountryId, CategoryId = product.CategoryId, BrandId = product.BrandId, Name = product.Name, Price = product.Price, Removed = product.Removed, Weight = product.Weight, Character = product.Character, Description = product.Description, Image = product.Image }, Characteristics = _productManager.GetCharacteristicsFromXml(product.Character) }; editModel = await SetDictionaries(editModel); return(View(editModel)); }
public async Task <IActionResult> Create(ProductCreateVM productCreateVM) { if (!ModelState.IsValid) { return(View(productCreateVM)); } if (!_image.IsImageValid(productCreateVM.MainPhotoFile)) { ModelState.AddModelError("", "Fayl .jpg/jpeg formatında və maksimum 3MB həcmində olmalıdır !"); return(View(productCreateVM)); } Car newCar = new Car { Name = productCreateVM.Name.Trim(), Year = productCreateVM.Year, AirConditioner = productCreateVM.AirConditioner, GasType = productCreateVM.GasType.Trim(), Gear = productCreateVM.Gear.Trim(), PhotoUrl = await _image.UploadAsync(productCreateVM.MainPhotoFile, "files", "cars"), UrlId = _context.Cars.Count() + 1, IsActive = productCreateVM.IsActive }; await _context.Cars.AddAsync(newCar); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Product")); }
public IActionResult Create(ProductCreateVM productCreateVM) { var files = HttpContext.Request.Form.Files; string webRootPath = _webHostEnvironment.WebRootPath; string upload = webRootPath + CommonDefault.ImagePath; string fileName = Guid.NewGuid().ToString(); string extension = Path.GetExtension(files[0].FileName); using (var fileStream = new FileStream(Path.Combine(upload, fileName + extension), FileMode.Create)) { files[0].CopyTo(fileStream); } productCreateVM.Food.Image = fileName + extension; foreach (var item in productCreateVM.SelectListTagIds) { productCreateVM.Food.ProductTags.Add(new ProductTag() { TagId = item }); } _appDbContext.Foods.Add(productCreateVM.Food); _appDbContext.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Edit(int?id) { var product = _appDbContext.Foods.Find(id); var tags = _appDbContext.Tags.ToList(); var selectTags = product.ProductTags.Select(x => new Tag() { Id = x.Tag.Id, Name = x.Tag.Name }); var selectList = new List <SelectListItem>(); tags.ForEach(i => selectList.Add(new SelectListItem(i.Name, i.Id.ToString(), selectTags.Select(x => x.Id).Contains(i.Id)))); ProductCreateVM productVM = new ProductCreateVM() { Food = _appDbContext.Foods.FirstOrDefault(item => item.Id == id), CategorySelectList = _appDbContext.Categories.Select(item => new SelectListItem { Text = item.CategoryName, Value = item.Id.ToString() }), TagSelectList = selectList /* SelectListTagIds = Product..Select(sc => sc.CourseId)*/ }; return(View(productVM)); }
public ActionResult Create(ProductCreateVM vm) { try { ProductVM product = new ProductVM(); AutoMapper.Mapper.Map(vm, product); _productRepository.save(product); Response.StatusCode = 200; return(Json(new { param1 = 0, param2 = _MESSGES.SUCCESS })); } catch (Exception ex) { Response.StatusCode = 400; return(Json(new { param1 = 0, param2 = _MESSGES.ERROR })); throw ex; } }
public IActionResult Edit(ProductCreateVM productCreateVM) { var files = HttpContext.Request.Form.Files; string webRootPath = _webHostEnvironment.WebRootPath; var objProduct = _appDbContext.Foods.AsNoTracking().FirstOrDefault(pro => pro.Id == productCreateVM.Food.Id); if (files.Count > 0) { string upload = webRootPath + CommonDefault.ImagePath; string fileName = Guid.NewGuid().ToString(); string extension = Path.GetExtension(files[0].FileName); using (var fileStream = new FileStream(Path.Combine(upload, fileName + extension), FileMode.Create)) { files[0].CopyTo(fileStream); } productCreateVM.Food.Image = fileName + extension; } else { productCreateVM.Food.Image = objProduct.Image; } _appDbContext.Foods.Update(productCreateVM.Food); _appDbContext.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(ProductCreateVM createVM, IFormFile file) { if (!ModelState.IsValid) { return(View(createVM)); } if (file.Length > 0) { string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + DateTime.Now.ToString("yymmssff") + extension; string path = Path.Combine(wwwRootPath + "/image/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(fileStream); } createVM.ProductImage = fileName; } createVM.ProductSlug = _helpers.Slugify(createVM.ProductName); _command.Create(createVM); return(RedirectToAction("List")); }
public async Task <ActionResult> Create() //GET: /Products/Create { var product = new ProductCreateVM(); await SetProductCategorySelectListAsync(product); await SetCurrencySelectLists(product); return(View(product)); }
public IActionResult Create() { var productVM = new ProductCreateVM() { Categories = _categoryService.List() }; return(View(productVM)); }
// GET: Products/Create public async Task <IActionResult> Create() { var user = await _userManager.GetUserAsync(HttpContext.User); var viewModel = new ProductCreateVM() { Categories = await _context.ProductType.OrderBy(pt => pt.Label).ToListAsync() }; return(View(viewModel)); }
public IActionResult AddProduct(ProductCreateVM model) { //string uniqFileName = null; if (model.photo != null) { productRepo.AddProduct(model); return(RedirectToAction("AddProduct")); } return(RedirectToAction("ManageProducts")); }
public void Create(ProductCreateVM createVM) { _product.ProductImage = createVM.ProductImage; _product.ProductName = createVM.ProductName; _product.ProductPrice = createVM.ProductPrice; _product.ProductSku = createVM.ProductSku; _product.ProductSlug = createVM.ProductSlug; _product.CategoryId = createVM.CategoryId; _context.Add(_product); _context.SaveChanges(); }
public IActionResult Create(ProductCreateVM model) { if (ModelState.IsValid) { Product product = _mapper.Map <Product>(model); bool isSaved = _productManager.Add(product); if (isSaved) { return(RedirectToAction(nameof(Index))); } } return(View()); }
public IActionResult Create() { List <SelectListItem> categoryItemList = _categoryManager.GetAll().Select(c => new SelectListItem() { Value = c.Id.ToString(), Text = c.Name }).ToList(); ProductCreateVM model = new ProductCreateVM(); model.CategoryItemList = categoryItemList; return(View(model)); }
public IActionResult Edit(int?id) { ProductCreateVM productVM = new ProductCreateVM() { Product = _appDbContext.Products.Find(id), CategorySelectList = _appDbContext.Categories.Select(item => new SelectListItem { Text = item.CategoryName, Value = item.Id.ToString() }) }; return(View(productVM)); }
public IActionResult Create([FromBody] ProductCreateVM model) { DbProduct product = new DbProduct { CategoryId = model.CategoryId, Name = model.Name, Price = model.Price, Image = model.Image }; _context.Products.Add(product); _context.SaveChanges(); return(Ok(product)); }
//Product Create //[Authorize(Users = "admin")] public ActionResult Create() { try { ProductCreateVM vm = new ProductCreateVM(); var categories = _categoryRepository.GetAll(); List <CategoryVM> categoryList = new List <CategoryVM>(); AutoMapper.Mapper.Map(categories, categoryList); vm.Categories = categoryList; ViewBag.Categories = categoryList; return(View(vm)); } catch (Exception ex) { throw ex; } }
public IActionResult Create() { ProductCreateVM productVM = new ProductCreateVM() { Food = new Food(), CategorySelectList = _appDbContext.Categories.Select(item => new SelectListItem { Text = item.CategoryName, Value = item.Id.ToString() }), TagSelectList = _appDbContext.Tags.Select(item => new SelectListItem { Text = item.Name, Value = item.Id.ToString() }) }; return(View(productVM)); }
private async Task <ProductCreateVM> SetDictionaries(ProductCreateVM model) { const string id = "Id"; const string name = "Name"; var characterTask = _productManager.Characteristics(); var brandTask = _productManager.Brands(); var categorTask = _productManager.Categories(); var countryTask = _productManager.Countries(); await Task.WhenAll(characterTask, brandTask, categorTask, countryTask); model.AvailableCharacteristics = new SelectList(await characterTask, id, name); model.Brands = new SelectList(await brandTask, id, name); model.Categories = new SelectList(await categorTask, id, name); model.Countries = new SelectList(await countryTask, id, name); return(model); }
public IActionResult UpdateProduct(int id) { Product pro = productRepo.GetProductByID(id); ProductCreateVM CPro = new ProductCreateVM { Id = pro.Id, Name = pro.Name, Desc = pro.Desc, Price = pro.Price, Category = pro.Category, ImageFive = pro.ImageFive, ImageFour = pro.ImageFour, ImageThree = pro.ImageThree, ImageTwo = pro.ImageTwo, ImageOne = pro.ImageOne }; return(View(CPro)); }
public IActionResult AddProduct(ProductCreateVM model) { //string uniqFileName = null; if (model.photoOne != null) { productRepo.AddProduct(model); //return RedirectToAction("AddProduct"); return(View()); } return(RedirectToAction("index")); }
public void AddProduct(ProductCreateVM model) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Uploads"); string uniqFileName = Guid.NewGuid().ToString() + "_" + model.photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqFileName); model.photo.CopyTo(new FileStream(filePath, FileMode.Create)); Product pro = new Product { Name = model.Name, Price = model.Price, Image = uniqFileName, Type = model.Type, Category = model.Category }; db.Products.Add(pro); db.SaveChanges(); }
public IActionResult Create(ProductCreateVM item) { try { Product product = new Product(); product.Title = item.Title; product.Description = item.Description; product.Price = item.Price; product.Avatar = item.Avatar; product.Balance = item.Balance; product.ImageUrl = item.ImageUrl; productService.InsertProduct(product); return(Ok(new ResponseManager { Message = "Success", IsSuccess = true })); } catch (Exception ex) { return(Ok(new ResponseManager { Message = "Something went wrong", IsSuccess = false })); } }
public IActionResult UpdateProduct(ProductCreateVM UpdatedPro) { productRepo.Update(UpdatedPro); return(RedirectToAction("ManageProducts", "products")); }
public void AddProduct(ProductCreateVM product) { //add image folders string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Uploads"); //if it product and the user add Five photo if (product.Category != Collections.Category.Unit && product.Category != Collections.Category.AirCompressor && product.photoOne != null && product.photoTwo != null && product.photoThree != null && product.photoFour != null && product.photoFive != null) { //add image one string uniqFileNameOne = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoOne.FileName); string filePathOne = Path.Combine(uploadsFolder, uniqFileNameOne); product.photoOne.CopyTo(new FileStream(filePathOne, FileMode.Create)); //add image two string uniqFileNameTwo = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoTwo.FileName); string filePathTwo = Path.Combine(uploadsFolder, uniqFileNameTwo); product.photoOne.CopyTo(new FileStream(filePathTwo, FileMode.Create)); //add image three string uniqFileNameThree = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoThree.FileName); string filePathThree = Path.Combine(uploadsFolder, uniqFileNameThree); product.photoOne.CopyTo(new FileStream(filePathThree, FileMode.Create)); //add image Four string uniqFileNameFour = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoFour.FileName); string filePathFoure = Path.Combine(uploadsFolder, uniqFileNameFour); product.photoFour.CopyTo(new FileStream(filePathFoure, FileMode.Create)); //add image Five string uniqFileNameFive = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoFive.FileName); string filePathFive = Path.Combine(uploadsFolder, uniqFileNameFive); product.photoOne.CopyTo(new FileStream(filePathFive, FileMode.Create)); Product pro = new Product { Name = product.Name, Price = product.Price, Desc = product.Desc, ImageOne = uniqFileNameOne, ImageTwo = uniqFileNameTwo, ImageThree = uniqFileNameThree, ImageFour = uniqFileNameFour, ImageFive = uniqFileNameFive, Category = product.Category }; db.Products.Add(pro); } //if it Compressor product and the user add two photo if (product.Category == Collections.Category.AirCompressor && product.photoOne != null && product.photoTwo != null) { //add image one string uniqFileNameOne = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoOne.FileName); string filePathOne = Path.Combine(uploadsFolder, uniqFileNameOne); product.photoOne.CopyTo(new FileStream(filePathOne, FileMode.Create)); //add image two string uniqFileNameTwo = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoTwo.FileName); string filePathTwo = Path.Combine(uploadsFolder, uniqFileNameTwo); product.photoOne.CopyTo(new FileStream(filePathTwo, FileMode.Create)); Product pro = new Product { Name = product.Name, Price = product.Price, Desc = product.Desc, ImageOne = uniqFileNameOne, ImageTwo = uniqFileNameTwo, Category = product.Category }; db.Products.Add(pro); } //if it unit product and the user add one photo if (product.Category == Collections.Category.Unit && product.photoOne != null) { //add image one string uniqFileNameOne = Guid.NewGuid().ToString() + "_" + Path.GetFileName(product.photoOne.FileName); string filePathOne = Path.Combine(uploadsFolder, uniqFileNameOne); product.photoOne.CopyTo(new FileStream(filePathOne, FileMode.Create)); Product pro = new Product { Name = product.Name, Price = product.Price, Desc = product.Desc, ImageOne = uniqFileNameOne, Category = product.Category }; db.Products.Add(pro); } db.SaveChanges(); }
public async Task <ActionResult> Create(ProductCreateVM createModel) { if (createModel?.Product == null) { ModelState.AddModelError(string.Empty, "Please fill in the required fields"); createModel = await SetDictionaries(createModel ?? new ProductCreateVM()); return(View(createModel)); } createModel = await SetDictionaries(createModel); if (!ModelState.IsValid) { if (createModel.Characteristics == null) { return(View(createModel)); } ValidateCharacteristics(createModel.Characteristics); return(View(createModel)); } OperationResult result = await _productManager.CreateAsync(new ProductCreateDTO { ProductCharacteristics = createModel.Characteristics, Product = new ProductDTO { Id = createModel.Product.Id, CountryId = createModel.Product.CountryId, CategoryId = createModel.Product.CategoryId, BrandId = createModel.Product.BrandId, Description = createModel.Product.Description, Name = createModel.Product.Name, Price = createModel.Product.Price, Removed = createModel.Product.Removed, Weight = createModel.Product.Weight }, ProductImage = createModel.Image }); // var toastOpt = new NotyOptions // { // Timeout = 15000, // ProgressBar = true // }; // // if (result.Type == ResultType.Success) // { // toastOpt.Timeout = 5000; // _toast.AddSuccessToastMessage("Product successfully created.", toastOpt); // } // else if (result.Type == ResultType.Warning) // { // string warMsg = result.Any(s => !string.IsNullOrWhiteSpace(s)) // ? result.BuildMessage() // : "The product has been created with warnings."; // _toast.AddWarningToastMessage(warMsg, toastOpt); // } if (result.Type == ResultType.Success) { return(RedirectToAction(nameof(List))); } if (result.All(string.IsNullOrWhiteSpace)) { result.Append("The product has been created with warnings."); } AddMessages(result.ToArray()); return(View(createModel)); }
public async Task <ActionResult> Edit(ProductCreateVM editModel) { if (editModel?.Product == null) { ModelState.AddModelError(string.Empty, "Product not found"); editModel = await SetDictionaries(editModel ?? new ProductCreateVM()); return(View(editModel)); } editModel = await SetDictionaries(editModel); if (!ModelState.IsValid) { if (editModel.Characteristics == null) { return(View(editModel)); } ValidateCharacteristics(editModel.Characteristics); return(View(editModel)); } OperationResult result = await _productManager.Edit(new ProductCreateDTO { ProductCharacteristics = editModel.Characteristics, Product = new ProductDTO { Id = editModel.Product.Id, CountryId = editModel.Product.CountryId, CategoryId = editModel.Product.CategoryId, BrandId = editModel.Product.BrandId, Description = editModel.Product.Description, Name = editModel.Product.Name, Price = editModel.Product.Price, Removed = editModel.Product.Removed, Weight = editModel.Product.Weight }, ProductImage = editModel.Image }); // var toastOpt = new NotyOptions // { // Timeout = 15000, // ProgressBar = true // }; // if (result.Type == ResultType.Success) // { // _toast.AddSuccessToastMessage("Product successfully edited.", toastOpt); // } // else if (result.Type == ResultType.Warning) // { // string warMsg = result.Any(s => !string.IsNullOrWhiteSpace(s)) // ? result.BuildMessage() // : "The product has been edited with warnings."; // _toast.AddWarningToastMessage(warMsg, toastOpt); // } // else if (result.Type == ResultType.Error) // { // string errMsg = result.Any(s => !string.IsNullOrWhiteSpace(s)) // ? result.BuildMessage() // : "The product has not been edited due to an unknown error."; // _toast.AddErrorToastMessage(errMsg, toastOpt); // } if (result.Type == ResultType.Success) { return(RedirectToAction(nameof(List))); } if (result.All(string.IsNullOrWhiteSpace)) { string msg = "The product has been edited with warnings."; if (result.Type == ResultType.Error) { msg = "The product has not been edited due an uknown error."; } result.Append(msg); } AddMessages(result.ToArray()); return(View(editModel)); }
public void Update(ProductCreateVM UpdatedProduct) { //add image folders string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Uploads"); Product OldProduct = db.Products.Find(UpdatedProduct.Id); OldProduct.Name = UpdatedProduct.Name; OldProduct.Price = UpdatedProduct.Price; OldProduct.Category = UpdatedProduct.Category; OldProduct.Desc = UpdatedProduct.Desc; db.SaveChanges(); //if it product and the user add Five photo if (UpdatedProduct.Category != Collections.Category.Unit && UpdatedProduct.Category != Collections.Category.AirCompressor) { if (UpdatedProduct.photoOne != null) { //add image one string uniqFileNameOne = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoOne.FileName); string filePathOne = Path.Combine(uploadsFolder, uniqFileNameOne); UpdatedProduct.photoOne.CopyTo(new FileStream(filePathOne, FileMode.Create)); OldProduct.ImageOne = uniqFileNameOne; } if (UpdatedProduct.photoTwo != null) { //add image two string uniqFileNameTwo = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoTwo.FileName); string filePathTwo = Path.Combine(uploadsFolder, uniqFileNameTwo); UpdatedProduct.photoTwo.CopyTo(new FileStream(filePathTwo, FileMode.Create)); OldProduct.ImageTwo = uniqFileNameTwo; } if (UpdatedProduct.photoThree != null) { //add image three string uniqFileNameThree = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoThree.FileName); string filePathThree = Path.Combine(uploadsFolder, uniqFileNameThree); UpdatedProduct.photoThree.CopyTo(new FileStream(filePathThree, FileMode.Create)); OldProduct.ImageThree = uniqFileNameThree; } if (UpdatedProduct.photoFour != null) { //add image Four string uniqFileNameFour = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoFour.FileName); string filePathFoure = Path.Combine(uploadsFolder, uniqFileNameFour); UpdatedProduct.photoFour.CopyTo(new FileStream(filePathFoure, FileMode.Create)); OldProduct.ImageFour = uniqFileNameFour; } if (UpdatedProduct.photoFive != null) { //add image Five string uniqFileNameFive = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoFive.FileName); string filePathFive = Path.Combine(uploadsFolder, uniqFileNameFive); UpdatedProduct.photoFive.CopyTo(new FileStream(filePathFive, FileMode.Create)); OldProduct.ImageFive = uniqFileNameFive; } db.SaveChanges(); } //if it Compressor product and the user add two photo if (UpdatedProduct.Category == Collections.Category.AirCompressor) { OldProduct.ImageOne = OldProduct.ImageOne; OldProduct.ImageTwo = OldProduct.ImageTwo; if (UpdatedProduct.photoOne != null) { //add image one string uniqFileNameOne = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoOne.FileName); string filePathOne = Path.Combine(uploadsFolder, uniqFileNameOne); UpdatedProduct.photoOne.CopyTo(new FileStream(filePathOne, FileMode.Create)); OldProduct.ImageOne = uniqFileNameOne; } if (UpdatedProduct.photoTwo != null) { //add image two string uniqFileNameTwo = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoTwo.FileName); string filePathTwo = Path.Combine(uploadsFolder, uniqFileNameTwo); UpdatedProduct.photoTwo.CopyTo(new FileStream(filePathTwo, FileMode.Create)); OldProduct.ImageTwo = uniqFileNameTwo; } db.SaveChanges(); } //if it unit product and the user add one photo if (UpdatedProduct.Category == Collections.Category.Unit && UpdatedProduct.photoOne != null) { //add image one string uniqFileNameOne = Guid.NewGuid().ToString() + "_" + Path.GetFileName(UpdatedProduct.photoOne.FileName); string filePathOne = Path.Combine(uploadsFolder, uniqFileNameOne); UpdatedProduct.photoOne.CopyTo(new FileStream(filePathOne, FileMode.Create)); //product.ImageOne = proToUpdate.ImageOne; OldProduct.ImageOne = uniqFileNameOne; db.SaveChanges(); } }