public JsonResult CreateProduct(CreateProductVM product) { Product prod = new Product(); prod.idCategory = Int32.Parse(product.ProductCategory); if (product.ProductTrademark != "0") { prod.IdTrademark = Int32.Parse(product.ProductTrademark); } else { prod.IdTrademark = null; } prod.ProductDescription = product.ProductDescription; prod.Cost = product.ProductCost; prod.WholeSalePrice = product.ProductWholeSalePrice; prod.UploadDate = DateTime.Today; prod.ProductState = product.ProductState; prod.ParcialStock = product.ProductStock; prod.Stock = product.ProductStock; prod.Minimum = product.ProductMinimum; db.Products.Add(prod); db.SaveChanges(); TempData["message"] = 6; return(new JsonResult { Data = new { status = true } }); }
public IActionResult CreateProduct(CreateProductVM createProductVM) { Product newProduct = new Product() { Id = DB.Products.Count + 1, Category = createProductVM.Category, Name = createProductVM.Name, Description = createProductVM.Description, Price = createProductVM.Price }; if (newProduct.Name == null || newProduct.Price == 0 || newProduct.Description == null || newProduct == null || newProduct.Category == 0) { return(RedirectToAction("CreateProduct", new { error = "The Product was NOT created successfully!!! Please try again!" })); } else { DB.Products.Add(newProduct); return(RedirectToAction("Index", "Home", new { message = "Product created successfully and added to the Data Base!" })); } }
public JsonResult CreateProduct(CreateProductVM vm) { try { Product newProduct = new Product(); newProduct.Created = DateTime.Now; newProduct.CreatedBy = SessionManager.ActiveUser.Id; newProduct.Modified = DateTime.Now; newProduct.ModifiedBy = SessionManager.ActiveUser.Id; newProduct.IsActive = true; newProduct.BrandName = vm.BrandName; newProduct.Model = vm.Model; newProduct.Serial = vm.Serial; newProduct.WorkHeight = vm.WorkHeight; newProduct.WorkCapacity = vm.WorkCapacity; newProduct.Periodic = vm.Periodic; newProduct.State = vm.State; newProduct.Description = vm.Description; _ps.Insert(newProduct); return(Json(new { Result = true, Message = "Ürün Başarıyla Kaydedildi." })); } catch (Exception ex) { return(Json(new { Result = false, ex.Message })); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,CategoryId,ForSale")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var viewModel = new CreateProductVM(); viewModel.Product = product; return(View(viewModel)); }
public IActionResult Create(CreateProductVM productVM) { if (!ModelState.IsValid) { return(View()); } //Create Image if (productVM.Products.ProductImage.Length > 0) { var uploads = Path.Combine(_environment.WebRootPath, "uploads"); using (var fileStream = new FileStream(Path.Combine(uploads, productVM.Products.ProductImage.FileName), FileMode.Create)) { productVM.Products.ProductImage.CopyTo(fileStream); } productVM.Products.ProductImagePath = productVM.Products.ProductImage.FileName.ToString(); } _productRepository.Insert(productVM.Products); try { _productRepository.Save(); } catch (Exception ex) { return(View(ex)); } return(RedirectToAction("Index")); }
// GET: Products/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var product = await _context.Product.FindAsync(id); if (product == null) { return(NotFound()); } var viewModel = new CreateProductVM() { AllCategories = _context.Category.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }) }; viewModel.Product = product; return(View(viewModel)); }
public async Task <ActionResult> CreateProduct(CreateProductVM productVM) { try { if (!ModelState.IsValid) { return(Json(new { error = true, message = "model is not valid" })); } if (productVM == null) { return(Json(new { error = true, message = "model is null" })); } // TODO: add transaction var product = await _productService.AddAsync(_mapper.Map <ProductDto>(productVM), productVM.StoreId) .ConfigureAwait(false); if (product == null) { return(Json(new { error = true, message = "product is null" })); } return(Json(new { error = false, name = product.Name, description = product.Description, productId = product.ProductId })); } catch (Exception ex) { _logger.LogError("CreateProduct fail", ex); return(Json(new { error = true, message = $"{ex?.ToString()}" })); } }
public IActionResult Create() { var model = new CreateProductVM(); PrepareViewModel(model); return(View(model)); }
public IHttpActionResult createProduct(CreateProductVM createProduct) { var customerIdMax = db.Products.Select(x => x.ProductID == db.Products.Max(m => m.ProductID)).ToList(); return(Ok(customerIdMax)); }
public OperationResult Create(CreateProductVM command) { OperationResult result = new OperationResult(); if (_productRepository.IsExist(p => p.Name == command.Name)) { return(result.Failed(ValidateMessage.IsDuplicatedName)); } var slug = command.Slug.Slugify(); var categorySlug = _categoryRepository.GetCategorySlugBy(command.CategoryId); var folderName = $"{categorySlug}//{slug}"; var pictureName = Uploader.ImageUploader(command.Picture, folderName, null !); var product = new Product(command.Name, command.Code, command.ShortDescription, command.Description, pictureName, command.PictureAlt, command.PictureTitle, command.CategoryId, slug, command.Keywords, command.MetaDescription); _productRepository.Create(product); _productRepository.SaveChanges(); return(result.Succeeded()); }
//DONE public ActionResult PostProduct(CreateProductVM model) { try { if (ModelState.IsValid) { if (model.BuyPrice > model.SellPrice) { return(BadRequest("El precio de venta de ser mayor al de compra")); } model.CreationDate = DateTime.Now; var productToCreate = _mapper.Map <Product>(model); var result = _productServices.addProduct(productToCreate); if (!result) { return(StatusCode(StatusCodes.Status500InternalServerError, "Algo salio mal, contacta el Administrador")); } return(Json("Producto creato con exito.!")); } return(BadRequest(GetErrorsFormated(ModelState))); } catch (Exception ex) { //TODO: Log the exception return(StatusCode(StatusCodes.Status500InternalServerError, "Algo salio mal, contacta el Administrador")); } }
public IActionResult Create(CreateProductVM newProduct) { Product product = new Product(); product.Name = newProduct.Name; product.Description = newProduct.Description; product.Price = newProduct.Price; product.CategoryID = newProduct.CategoryID; product.ProductImageMappings = new List <ProductImageMapping>(); string[] productImages = newProduct.ProductImages .Where(pi => !string.IsNullOrEmpty(pi)).ToArray(); for (int i = 0; i < productImages.Length; i++) { product.ProductImageMappings.Add(new ProductImageMapping { ProductImage = imgRepo.GetSingle(int.Parse(productImages[i])), // ProductImageID=int.Parse(productImages[i]), ImageNumber = i }); } if (ModelState.IsValid) { repository.Add(product); repository.Save(); return(RedirectToAction(nameof(Index))); } newProduct.CategoryList = new SelectList(catRepo.GetAll(), "ID", "Name", product.CategoryID); newProduct.ImageLists = new List <SelectList>(); for (int i = 0; i < Constants.NumberOfProductImages; i++) { newProduct.ImageLists.Add(new SelectList(imgRepo.GetAll(), "ID", "FileName", newProduct.ProductImages[i])); } return(View()); }
public IActionResult Edit(int id) { Product product = repository.GetSingle(id); product.ProductImageMappings = mapRepo .FindBy(m => m.ProductID == product.ID).ToList(); CreateProductVM model = new CreateProductVM(); model.CategoryList = new SelectList(catRepo.GetAll(), "ID", "Name", product.CategoryID); model.ImageLists = new List <SelectList>(); foreach (var imageMapping in product.ProductImageMappings .OrderBy(i => i.ImageNumber)) { model.ImageLists.Add(new SelectList(imgRepo.GetAll(), "ID", "FileName", imageMapping.ProductImageID)); } for (int i = product.ProductImageMappings.Count(); i < Constants.NumberOfProductImages; i++) { model.ImageLists.Add(new SelectList(imgRepo.GetAll(), "ID", "FileName")); } model.ID = product.ID; model.Name = product.Name; model.Description = product.Description; model.Price = product.Price; model.CategoryID = (int)product.CategoryID; return(View(model)); }
public ActionResult Create() { var vm = new CreateProductVM(); //Filling Required DropdownList's Populatelookups(vm); return(View(vm)); }
public ActionResult Post(CreateProductVM model) { Product product = GetMapper.Map <Product>(model); _context.Products.Add(product); _context.SaveChanges(); return(Ok()); }
//Get: /Product/Create public ActionResult Create() { CreateProductVM createProduct = new CreateProductVM(); createProduct.Categories = _shopRepository.GetCategories(); return(View("Create", createProduct)); }
public IActionResult Edit(CreateProductVM model) { Product productToUpdate = repository .AllIncluding(p => p.ProductImageMappings, x => x.Category).First(p => p.ID == model.ID); productToUpdate.CategoryID = model.CategoryID; productToUpdate.Name = model.Name; productToUpdate.Description = model.Description; productToUpdate.Price = model.Price; if (productToUpdate.ProductImageMappings == null) { productToUpdate.ProductImageMappings = new List <ProductImageMapping>(); } string[] productImages = model.ProductImages .Where(pi => !string.IsNullOrEmpty(pi)).ToArray(); for (int i = 0; i < productImages.Length; i++) { var imageMappingToEdit = productToUpdate.ProductImageMappings .Where(pim => pim.ImageNumber == i).FirstOrDefault(); var image = imgRepo.GetSingle(int.Parse(productImages[i])); if (imageMappingToEdit == null) { productToUpdate.ProductImageMappings.Add( new ProductImageMapping { ProductImage = image, ProductImageID = image.ID, ImageNumber = i }); } else { if (imageMappingToEdit.ProductImageID != int.Parse(productImages[i])) { imageMappingToEdit.ProductImage = image; } } } for (int i = productImages.Length; i < Constants.NumberOfProductImages; i++) { var imageMappingToEdit = productToUpdate .ProductImageMappings.Where(pim => pim.ImageNumber == i) .FirstOrDefault(); if (imageMappingToEdit != null) { mapRepo.Delete(imageMappingToEdit); } } repository.Edit(productToUpdate); repository.Save(); return(RedirectToAction(nameof(Index))); }
public IActionResult GetProductVMForInsert() { var prod = new CreateProductVM { Products = new Product(), Categories = _categoryRepository.GetAll().ToList() }; return(Ok(prod)); }
public ActionResult SaveNewBook(CreateProductVM productView) { Product product = _mapper.Map <Product>(productView); var currentUser = _userService.GetUser(HttpContext.User.Identity.Name); product.UserId = currentUser.Id; _productService.AddProduct(product); return(RedirectToAction("UserProfile", "PrivateOffice")); }
public ActionResult Create(CreateProductVM model) { var product = Mapper.Instance.Map <Product>(model); string currentUsername = User.Identity.Name; _shopRepository.CreateProduct(product, currentUsername); return(RedirectToAction("Index", "Product")); }
public IActionResult OnPostCreate(CreateProductVM command) { if (!ModelState.IsValid) { return(RedirectToPage("Index")); } var result = _productApplication.Create(command); return(new JsonResult(result)); }
public IActionResult Create() { var createProduct = new CreateProductVM { Products = new Product(), Categories = _categoryRepository.GetAll().ToList() }; return(View(createProduct)); }
public static Product CreateProduct(CreateProductVM createProductVM) { return(new Product() { Id = _productRepository.GetAll().Count + 1, Category = createProductVM.Category, Name = createProductVM.Name, Description = createProductVM.Description, Price = createProductVM.Price }); }
public IActionResult AddProduct(CreateProductVM model) { //string uniqFileName = null; if (model.PhotoBinary != null) { productRepo.AddProduct(model); return(RedirectToAction("AddProduct")); } return(RedirectToAction("ManageProducts")); }
// GET: Products/Create public IActionResult Create() { var ViewModel = new CreateProductVM() { AllCategories = _context.Category.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }) }; return(View(ViewModel)); }
public ActionResult CreateProduct(CreateProductVM input) { if (ModelState.IsValid) { input.Product.TestId = input.TestId; db.Products.Add(input.Product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TestId = new SelectList(db.Tests, "Id", "Name", input.TestId); return(View(input.Product)); }
public IActionResult Create() { CreateProductVM vModel = new CreateProductVM(); // vModel.CategoryList = new SelectList(imgRepo.GetAll(), "ID", "FileName"); vModel.CategoryList = new SelectList(catRepo.GetAll(), "ID", "Name"); vModel.ImageLists = new List <SelectList>(); for (int i = 0; i < Constants.NumberOfProductImages; i++) { vModel.ImageLists.Add(new SelectList(imgRepo.GetAll(), "ID", "FileName")); } return(View(vModel)); }
public void AddProduct(CreateProductVM model) { string imagePath = ImageHandeler.UploadImage(model.PhotoBinary, hostingEnvironment.WebRootPath); Product pro = new Product { Name = model.Name, Price = model.Price, Image = imagePath, Type = model.Type, Category = model.Category }; db.Products.Add(pro); db.SaveChanges(); }
public ActionResult CreateProduct() { using (ShoppingDBEntities dbobj = new ShoppingDBEntities()) { var products = dbobj.tblProducts.ToList(); CreateProductVM objcreateProductVM = new CreateProductVM(); objcreateProductVM.product = new tblProduct(); objcreateProductVM.products = products; objcreateProductVM.ProductModel = new ProductModel(); return View(objcreateProductVM); } }
public IActionResult CreateProduct(CreateProductVM createProductVM) { Product newProduct = _productService.CreateProduct(createProductVM); if (!ModelState.IsValid) { return(RedirectToAction("CreateProduct", new { error = "The Product was NOT created successfully!!! Please try again!" })); } else { _productService.InsertProduct(newProduct); return(RedirectToAction("Index", "Home", new { message = "Product created successfully and added to the Data Base!" })); } }