public IActionResult Edit(HttpResponse response, HttpSession session, EditProductBindingModel model, int knifeId) { var user = AuthenticationManager.GetAuthenticatedUser(session.Id); if (user == null) { this.Redirect(response, "/login/login"); return(null); } var service = new ProductsService(Data.Data.Context); var knife = service.IsKnifeIdExist(knifeId); if (knife == null) { this.Redirect(response, "/home/index"); return(null); } service.Update(model, knifeId); this.Redirect(response, "/admin/index"); return(null); }
public async Task EditProduct_WithCorrectData_ShouldEditProductSuccessfully() { string onFalseErrorMessage = "The method returned false upon correct data for edit."; string onNullErrorMessage = "The edited product was not in the database"; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var cloudinaryServiceMock = new Mock <ICloudinaryService>(); var productService = new ProductService(context, cloudinaryServiceMock.Object); // Get the product and seed it var product = this.GetProduct(); await this.SeedSingleProduct(context); EditProductBindingModel model = new EditProductBindingModel { Id = product.Id, Name = "NewName", Price = 12, Specification = "NewSpec", Description = "NewDesc", }; var methodResult = await productService.EditProduct(model); Assert.True(methodResult, onFalseErrorMessage); var productFromDatabase = await context.Products.FirstOrDefaultAsync( p => p.Id == product.Id && p.Name == model.Name && p.Price == model.Price && p.Specification == model.Specification && p.Description == model.Description); AssertExtensions.NotNullWithMessage(productFromDatabase, onNullErrorMessage); }
public async Task <int> EditProductAsync(EditProductBindingModel model) { var product = this.DbContext .Products .FirstOrDefault(x => x.Id == model.Id); if (product == null) { return(ErrorId); } product.Description = model.Description; product.PhotoURL = model.PhotoURL; product.HighLightVideoURL = model.HighLightVideoURL; product.AdditionalInfoURL = model.AdditionalInfoURL; product.Price = model.Price; if (product.HighLightVideoURL.Contains(CommonConstants.OriginalVideoUrlPart)) { product.HighLightVideoURL = ModifyVideoURL_Embeded.ModifyEmbed(product.HighLightVideoURL); } await this.DbContext.SaveChangesAsync(); return(product.Id); }
public async Task <IActionResult> Edit(EditProductBindingModel model) { await this.productService.EditProduct(model); this.TempData["Success"] = $"Successully edited {model.Name}"; return(this.RedirectToAction("All")); }
public ActionResult EditProduct(EditProductBindingModel product) { if (ModelState.IsValid) { this.service.UpdateProduct(product); this.TempData["ProductDeleted"] = "Product has been updated successfully!!!"; } return(this.RedirectToAction("Index", "Home", new { area = "" })); }
public void UpdateProduct(EditProductBindingModel bind) { Knive knive = this.context.Knives.Find(bind.Id); knive.Price = bind.Price; knive.ImageUrl = bind.ImageUrl; knive.Name = bind.Name; this.context.SaveChanges(); }
public async Task UpdateProduct(EditProductBindingModel input) { var product = await this.context.Products.FirstOrDefaultAsync(x => x.Id == input.Id); product.Name = input.Name; product.Price = input.Price; product.ProductUrl = input.ProductUrl; product.Quantity = input.Quantity; await this.context.SaveChangesAsync(); }
public async Task <IActionResult> ProductSingleEdit(EditProductBindingModel input) { if (!this.ModelState.IsValid) { return(await this.ProductSingleEdit(input.Id)); } await this.productService.UpdateProduct(input); return(this.Redirect("/Admin/ProductEdit")); }
public async Task <bool> EditProduct(EditProductBindingModel model) { var product = await this.context.Products.SingleOrDefaultAsync(p => p.Id == model.Id); AutoMapper.Mapper.Map(model, product); this.context.Products.Update(product); var result = await this.context.SaveChangesAsync(); return(result > 0); }
public void Update(EditProductBindingModel model, int knifeId) { var knife = this.context.Knives.Find(knifeId); if (!string.IsNullOrEmpty(model.Name)) { knife.Name = model.Name; } if (!string.IsNullOrEmpty(model.ImageUrl)) { knife.ImageURL = model.ImageUrl; } this.context.SaveChanges(); }
public void UpdateProduct(EditProductBindingModel product) { Tyre tyre = null; Wheel wheel = null; var curProduct = this.Data.Products.Find(product.Id); if (curProduct.GetType().BaseType.Name == "Tyre") { tyre = (Tyre)curProduct; tyre.Brand = product.Brand; tyre.Model = product.Model; tyre.Price = product.Price; tyre.Stock = product.Stock; tyre.Height = product.Height; tyre.Season = product.Season; tyre.Width = product.Width; tyre.Size = product.Size; tyre.Description = product.Description; if (product.ImageUrl != null) { byte[] file = this.FileUpload(product.ImageUrl); tyre.ImageUrl = file; } this.Data.Products.Update(tyre); } else if (curProduct.GetType().BaseType.Name == "Wheel") { wheel = curProduct as Wheel; wheel.Brand = product.Brand; wheel.Model = product.Model; wheel.Price = product.Price; wheel.Stock = product.Stock; wheel.PCD = product.PCD; wheel.Description = product.Description; wheel.Size = product.Size; if (product.ImageUrl != null) { byte[] file = this.FileUpload(product.ImageUrl); wheel.ImageUrl = file; } this.Data.Products.Update(wheel); } this.Data.SaveChanges(); }
public IActionResult Edit(HttpSession session, HttpResponse response, EditProductBindingModel bind) { User user = AuthenticationManager.GetAuthenticatedUser(session.Id); if (user == null) { this.Redirect(response, "/login/login"); return(null); } ProductsService service = new ProductsService(Data.Data.Context); service.UpdateProduct(bind); this.Redirect(response, "/admin/index"); return(null); }
public async Task <IActionResult> EditProduct(EditProductBindingModel model) { if (!this.ModelState.IsValid) { SetErrorMessage(CommonConstants.DangerMessage); return(this.EditProduct(model.Id)); } int generatedId = await this.productService.EditProductAsync(model); if (generatedId < 1) { return(RedirectToAction(RedirectConstants.IndexSuffix)); } return(Redirect(string.Format(RedirectConstants.AdministratorAreaProductDetailsPage, generatedId))); }
public IActionResult Edit(EditProductBindingModel model) { if (!this.IsValidModel(model)) { this.ViewData[ErrorKey] = InvalidProductCreationMessage; return(this.View()); } int id = model.Id; using (this.Context) { Product product = this.Context.Products.Include(x => x.ProductType).FirstOrDefault(x => x.Id == id); if (product == default(Product)) { this.ViewData[ErrorKey] = NonExistingProductMessage; this.ViewData[NameKey] = string.Empty; this.ViewData[PriceKey] = string.Empty; this.ViewData[DescriptionKey] = string.Empty; this.ViewData[RadioButtonsKey] = string.Empty; return(this.View()); } product.Name = model.Name; product.Description = model.Description; ProductType productType = this.Context.ProductTypes.FirstOrDefault(x => x.ProductTypeName == model.ProductType); product.ProductType = productType; product.ProductTypeId = productType.Id; decimal price = 0; bool validPrice = decimal.TryParse(model.Price, out price); product.Price = price; this.Context.SaveChanges(); return(RedirectToHome); } }
public async Task UpdateProductTests() { //Arrange var mapperConfig = new MapperConfiguration(x => x.AddProfile(new MappingProfile())); var mapper = mapperConfig.CreateMapper(); var productService = new ProductService(this.context, mapper); var firstProduct = new Product { Description = "Some Description", Name = "FirstProductName", Price = 12.2m, ProductUrl = "URL", CategoryId = "CategoryId", PurchaseCount = 5, Quantity = 5, }; await this.context.Products.AddAsync(firstProduct); await this.context.SaveChangesAsync(); var newInputModel = new EditProductBindingModel { Quantity = 10, ProductUrl = "NewProductUrl", Id = firstProduct.Id, Name = "NewProductName", Price = 111.11m, }; //Act Assert.Equal(1, this.context.Products.Count()); await productService.UpdateProduct(newInputModel); //Assert Assert.Equal("NewProductUrl", firstProduct.ProductUrl); Assert.Equal(111.11m, firstProduct.Price); Assert.Equal(10, firstProduct.Quantity); Assert.Equal("NewProductName", firstProduct.Name); }
public async Task <IActionResult> DeleteProduct(EditProductBindingModel model) { bool isDeleted = await this.productService.DeleteProductAsync(model.Id); return(RedirectToAction(RedirectConstants.IndexSuffix)); }