public IActionResult Edit(int id, ProductCreateBindingModel model) { if (!this.IsAdmin) { return(this.RedirectToLogin()); } if (!this.IsValidModel(model)) { SetValidatorErrors(); return(this.Edit(id)); } ProductType productType = this.products.GetProductType(model.Type); if (productType == null) { this.ShowError(Constants.InvalidProductTypeMessage); return(this.Edit(id)); } this.products.Update(id, model.Name, model.Price, model.Description, productType); this.ViewData["id"] = id.ToString(); return(this.RedirectToHome()); }
public async Task <IActionResult> Create(ProductCreateBindingModel productCreateInputModel) { if (!this.ModelState.IsValid) { var allProductTypes = await this.productService.GetAllProductTypes().ToListAsync(); this.ViewData["types"] = allProductTypes .Select(productType => new ProductCreateProductTypeViewModel { Name = productType.Name, }) .ToList(); return(this.View()); } string pictureUrl = await this.cloudinaryService .UploadPictureAync(productCreateInputModel.Picture, productCreateInputModel.Name); ProductServiceModel productServiceModel = AutoMapper.Mapper.Map <ProductServiceModel>(productCreateInputModel); productServiceModel.Picture = pictureUrl; await this.productService.Create(productServiceModel); return(this.Redirect("/")); }
public IActionResult Add(ProductCreateBindingModel model) { if (!this.User.IsInRole("Admin")) { return(RedirectToHome()); } if (!this.IsValidModel(model)) { SetValidatorErrors(); return(this.View()); } ProductType productType = this.products.GetProductType(model.Type); if (productType == null) { this.ShowError(Constants.InvalidProductTypeMessage); return(this.View()); } var id = this.products.Create(model.Name, model.Price, model.Description, productType); if (id == default(int)) { ShowError(Constants.UnsuccessfullOperationMessage); return(this.View()); } return(RedirectToAction($"/products/details?id={id}")); }
public IActionResult Create(ProductCreateBindingModel productCreateBindingModel) { if (!ModelState.IsValid) { return(View()); } this.productService.CreateProduct(productCreateBindingModel.To <Product>()); return(this.Redirect("All")); }
public IActionResult Create(ProductCreateBindingModel productCreateBindingModel) { if (!this.ModelState.IsValid) { // TODO: SAVE FORM RESULT return(this.View()); } this.productService.CreateProduct(productCreateBindingModel.To <Product>()); return(this.Redirect("All")); }
public IActionResult Create(ProductCreateBindingModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("/Products/Create")); } var product = ModelMapper.ProjectTo <Product>(model); this.productService.CreateProduct(product); return(this.Redirect("/Products/All")); }
public async Task <IActionResult> Create(ProductCreateBindingModel productCreateBindingModel) { ProductServiceModel productServiceModel = new ProductServiceModel { Name = productCreateBindingModel.Name, Price = productCreateBindingModel.Price, Category = new CategoryServiceModel() { Name = productCreateBindingModel.Category }, Picture = await cloudinaryService.UploadFile(productCreateBindingModel.Picture) }; productService.Create(productServiceModel); return(Redirect("/")); }
public async Task <IActionResult> Create(ProductCreateBindingModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var serviceProduct = new ProductCreateServiceModel { Name = model.Name, Price = model.Price, ImageUrl = model.ImageUrl }; await this.productsService.CreateAsync(serviceProduct); return(this.RedirectToAction("Index", "Home")); }