public async Task <IActionResult> AddPictures(int id) { var loggedUserId = this.userManager.GetUserId(User); var productToAddPictures = await this.productService.GetProductByIdAsync(id); if (productToAddPictures == null) { return(NotFound()); } if (!IsUserAuthorizedToEdit(productToAddPictures.OwnerId, loggedUserId)) { return(Forbid()); } var model = new ProductFormModel { Id = productToAddPictures.Id, Name = productToAddPictures.Name, Description = productToAddPictures.Description, Pictures = productToAddPictures.Pictures }; return(View(model)); }
public ActionResult HotelEdit(ProductFormModel productToEdit, bool continueEditing) { if (ModelState.IsValid) { //Mapping to domain Product product = Mapper.Map <ProductFormModel, Product>(productToEdit); if (String.IsNullOrEmpty(product.Slug)) { product.Slug = StringConvert.ConvertShortName(product.Name); } //this funcion not update all relationship value. _productService.EditProduct(product); //update attribute foreach (var mapping in product.ProductAttributeMappings) { _productAttributeMappingService.EditProductAttributeMapping(mapping); } //update productpicture URL foreach (var picture in product.ProductPictureMappings) { _productPictureMappingService.EditProductPictureMapping(picture); _pictureService.EditPicture(picture.Picture); } return(continueEditing ? RedirectToAction("HotelEdit", "Product", new { productId = product.Id }) : RedirectToAction("Hotel", "Product")); } else { var listProductCategory = _productCategoryService.GetProductCategories().Where(c => !c.Name.Contains("Tour")).ToSelectListItems(-1); productToEdit.ListProductCategory = listProductCategory; return(View("HotelEdit", productToEdit)); } }
public ActionResult Edit(int productId) { Product product = _productService.GetProductById(productId); var listProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1); //var vendorid = product.VendorId != null ? -1 : product.VendorId; var listVendor = _VendorService.GetVendors().ToSelectListItems(product.VendorId); //var promotionid = product.PromotionId != null ? -1 : product.VendorId; var ListPromotion = _PromotionService.GetPromotions().ToSelectListItems(product.PromotionId); //var locationid = product.LocationId != null ? -1 : product.VendorId; //var ListLocation = _LocationService.GetLocations().ToSelectListItems(product.LocationId); var ListColor = _ColorService.GetColors().ToSelectListItems(product.ColorId); ProductFormModel model = new ProductFormModel(); model.CategoryId = product.ProductCategoryMappings.FirstOrDefault().ProductCategoryId; model.CategoryId2 = product.ProductCategoryMappings.LastOrDefault().ProductCategoryId; model.ListProductCategory = listProductCategory; //model.Location = ListLocation; model.Promotion = ListPromotion; model.Vendor = listVendor; model.ListColors = ListColor; model.product = product; return(View(model: model)); }
public IActionResult Edit(int?id) { try { var viewModel = new ProductFormModel(); if (id.HasValue) { var product = _productService.GetProduct(id.Value); if (product == null) { TempData["InfoMessage"] = AppStrings.ProductNotFoundMessage; return(RedirectToAction(nameof(Index))); } viewModel = _mapper.Map <ProductFormModel>(product); } viewModel.ProductModelSelectItems = _productService.GetAllProductModels() .Select(x => new SelectListItem { Value = x.ProductModelId.ToString(), Text = x.Name }); return(View("ProductForm", viewModel)); } catch (Exception ex) { _logger.LogMessage(ex.Message); TempData["ErrorMessge"] = AppStrings.GenericErrorMsg; return(RedirectToAction(nameof(Index))); } }
public Product(ProductFormModel productFormModel, MediaImage reciept) { Identifier = productFormModel.Identifier; ShopNo = productFormModel.ShopNo; DateOfPurchase = productFormModel.DateOfPurchase; Reciept = reciept; GenerateLuckyNumbers(); }
public ActionResult HotelEdit(int productId) { var product = _productService.GetProductById(productId); ProductFormModel productFormModel = Mapper.Map <Product, ProductFormModel>(product); productFormModel.ListProductCategory = _productCategoryService.GetProductCategories().Where(c => !c.Name.Contains("Tour")).ToSelectListItems(-1); productFormModel.ListProducts = _productService.GetAllProducts().ToSelectListItems(-1); return(View(model: productFormModel)); }
public ActionResult TourCreate() { //Get the list category var listProductCategory = _productCategoryService.GetProductCategories().Where(c => c.Name.Contains("Tour")).ToSelectListItems(-1); var product = new ProductFormModel { ListProductCategory = listProductCategory }; return(View(product)); }
public ActionResult Create() { //Get the list category var listProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1); var product = new ProductFormModel { ListProductCategory = listProductCategory }; return(View(product)); }
public ActionResult Add() { var viewModel = new ProductFormModel { Product = new Product(), Header = "Dodaj nowy produkt" }; return(View("ProductForm", viewModel)); }
public async Task <IActionResult> Create(ProductFormModel model, IFormFile file) { if (!ModelState.IsValid) { return(View(model)); } await this.products.Create(model.Name, model.Category, model.Energy, model.Fat , model.Protein, model.Sugars, file); return(RedirectToAction(nameof(Index))); }
//ua trang nao quen roi public ActionResult Create() { //Get the list category var listProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1); Product product = new Product(); ProductFormModel model = new ProductFormModel(); model.ListProductCategory = listProductCategory; model.product = product; return(View(model)); }
public async Task <IActionResult> Edit(ProductFormModel model) { if (!ModelState.IsValid) { return(View(model)); } await this.productService .EditAsync(model.Id, model.Name, model.Description); return(RedirectToAction(string.Concat(nameof(ProductController.Details), "/", model.Id), "Product")); }
public async Task <ActionResult> Create(ProductFormModel model, HttpPostedFileBase file) { if ((model.stock.price != null && model.stock.quantity == null) || (model.stock.price == null && model.stock.quantity != null)) { return(View(model)); } System.Diagnostics.Debug.WriteLine("mesure : " + model.product.mesure); if (ModelState.IsValid) { if (file != null) { model.product.imageUrl = file.FileName; var path1 = Path.Combine(Server.MapPath("~/ProductImages/"), file.FileName); var path2 = Path.Combine(Server.MapPath("~/ResizedProductImages/"), file.FileName); var path3 = Path.Combine(Server.MapPath("~/ResizedProductImagesForCartNotif/"), file.FileName); Image image = Image.FromStream(file.InputStream, true, true); var img1 = ResizeImage(image, 720, 960); var img2 = ResizeImage(image, 1200, 1600); var img3 = ResizeImage(image, 320, 320); img1.Save(path1, ImageFormat.Png); img2.Save(path2, ImageFormat.Png); img3.Save(path3, ImageFormat.Png); } var productJson = await Task.Run(() => JsonConvert.SerializeObject(model.product)); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:8080/springboot-crud-rest/api/v1/"); var content = new StringContent(productJson.ToString(), Encoding.UTF8, "application/json"); HttpResponseMessage response; response = client.PostAsync("product", content).Result; Product product = response.Content.ReadAsAsync <Product>().Result; var UserLoggedIn = (UserRegisterModel)Session["User"]; if (model.stock.price != null && model.stock.quantity != null) { model.stock.product = product; model.stock.supplier = new Supplier(); model.stock.supplier.userId = UserLoggedIn.userId; var stockJson = await Task.Run(() => JsonConvert.SerializeObject(model.stock)); HttpClient client1 = new HttpClient(); client1.BaseAddress = new Uri("http://localhost:8080/springboot-crud-rest/api/v1/"); var content1 = new StringContent(stockJson.ToString(), Encoding.UTF8, "application/json"); HttpResponseMessage response1; response1 = client.PostAsync("stockfornewproduct", content1).Result; } return(Redirect("/Stock/Index")); } return(View(model)); }
public ActionResult TourCreate(ProductFormModel newProduct, bool continueEditing) { if (ModelState.IsValid) { //Mapping to domain Product product = Mapper.Map <ProductFormModel, Product>(newProduct); if (String.IsNullOrEmpty(product.Slug)) { product.Slug = StringConvert.ConvertShortName(product.Name); } //Create Product _productService.CreateProduct(product); //Add ProductAttribute after product created product.ProductAttributeMappings = new Collection <ProductAttributeMapping>(); var listAttributeId = _productAttributeService.GetProductAttributes().Where(p => p.Type.Equals("Tour")).Select(p => p.Id); foreach (var id in listAttributeId) { product.ProductAttributeMappings.Add( new ProductAttributeMapping() { ProductAttributeId = id, ProductId = product.Id }); } //Add Picture default for Labixa product.ProductPictureMappings = new Collection <ProductPictureMapping>(); for (int i = 0; i < 11; i++) { var newPic = new Picture(); bool ismain = i == 0; _pictureService.CreatePicture(newPic); product.ProductPictureMappings.Add( new ProductPictureMapping() { PictureId = newPic.Id, ProductId = product.Id, IsMainPicture = ismain, DisplayOrder = 0, }); } _productService.EditProduct(product); return(continueEditing ? RedirectToAction("TourEdit", "Product", new { productId = product.Id }) : RedirectToAction("Tour", "Product")); } else { var listProductCategory = _productCategoryService.GetProductCategories().Where(c => !c.Name.Contains("Tour")).ToSelectListItems(-1); newProduct.ListProductCategory = listProductCategory; return(View("TourCreate", newProduct)); } }
public async Task EditAsyncShouldSaveProductChanges() { //Arrange const int id = 1; const string nameVaue = "Name"; const string descriptionValue = "Description"; const int brandId = 1; const int categoryId = 1; const string imageUrlValue = "ImageUrl"; const decimal priceValue = 5; const ProductCondition condition = ProductCondition.BrandNew; var product = new Product() { Id = id, Category = new Category(), Brand = new Brand() }; var productFormModel = new ProductFormModel { Name = nameVaue, BrandId = brandId, CategoryId = categoryId, Description = descriptionValue, ImageUrl = imageUrlValue, Price = priceValue, Condition = condition }; //Act this.context.Add(product); await this.context.SaveChangesAsync(); var result = await this.adminProductService.EditAsync(id, productFormModel); var productAfterChanges = this.context .Products .Find(id); //Assert result .Should() .BeTrue(); Assert.Same(product.Name, nameVaue); Assert.Equal(product.BrandId, brandId); Assert.Equal(product.CategoryId, categoryId); Assert.Same(product.Description, descriptionValue); Assert.Same(product.ImageURL, imageUrlValue); Assert.Equal(product.Price, priceValue); Assert.Equal(product.Condition, condition); }
public ActionResult Edit(int productId) { var product = _productService.GetProductById(productId); ProductFormModel productFormModel = Mapper.Map <Product, ProductFormModel>(product); productFormModel.ListProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1); productFormModel.ListProducts = _productService.GetAllProducts().ToSelectListItems(-1); var list = _productRelationShipService.GetProductById(productId); //productFormModel.Id1 = list.ToList()[0].ProductRelateId; //productFormModel.Id2 = list.ToList()[1].ProductRelateId; //productFormModel.Id3 = list.ToList()[2].ProductRelateId; return(View(model: productFormModel)); }
public async Task EditAsyncShouldReturnFalseWhenProductIdIsNotExisting() { //Arrange var unexistingProductId = 1; ProductFormModel productForm = null; //Act var result = await this.adminProductService.EditAsync(unexistingProductId, productForm); //Assert result .Should() .BeFalse(); }
public ActionResult Edit(ProductFormModel productToEdit, bool continueEditing) { if (ModelState.IsValid) { //Mapping to domain Product product = productToEdit.product; product.Slug = product.Slug + "-" + product.Id; if (productToEdit.CategoryId != 0) { var obj = _ProductCategoryMappingService.GetProductCategoryMappings().Where(p => p.ProductId == productToEdit.product.Id); obj.FirstOrDefault().ProductCategoryId = productToEdit.CategoryId; _ProductCategoryMappingService.EditProductCategoryMapping(obj.FirstOrDefault()); } //if (productToEdit.CategoryId2 != 0) //{ // var obj = _ProductCategoryMappingService.GetProductCategoryMappings().Where(p => p.ProductId == productToEdit.product.Id); // obj.LastOrDefault().ProductCategoryId = productToEdit.CategoryId; // _ProductCategoryMappingService.EditProductCategoryMapping(obj.LastOrDefault()); //} //Product product = Mapper.Map<ProductFormModel, Product>(productToEdit.product); if (String.IsNullOrEmpty(product.Slug)) { product.Slug = StringConvert.ConvertShortName(product.Name); } //this funcion not update all relationship value. _productService.EditProduct(product); //update attribute foreach (var mapping in product.ProductAttributeMappings) { _productAttributeMappingService.EditProductAttributeMapping(mapping); } //update productpicture URL foreach (var picture in product.ProductPictureMappings) { _productPictureMappingService.EditProductPictureMapping(picture); _pictureService.EditPicture(picture.Picture); } //add tour relation return(continueEditing ? RedirectToAction("Edit", "Product", new { productId = product.Id }) : RedirectToAction("Index", "Product")); } else { var listProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1); productToEdit.ListProductCategory = listProductCategory; return(RedirectToAction("Edit", new{ productId = productToEdit.product.Id })); } }
public ActionResult Delete([DataSourceRequest] DataSourceRequest request, ProductFormModel model) { Contract.Requires(model != null); var order = this.ProductRepository.GetQueryable().SingleOrDefault(s => s.Id == model.Id); if (order == null) { throw new NullReferenceException("Objednavka nenalezena."); } this.ProductRepository.Delete(order); this.UnityOfWork.Save(); return(this.JsonNet(new[] { model }.ToDataSourceResult(request, this.ModelState))); }
public ViewResult Add() { ProductFormModel productForm = new ProductFormModel(); foreach (var category in _categoryRepository.AllCategory) { productForm.Categories.Add( new SelectListItem { Value = category.CategoryId.ToString(), Text = category.Name });; } return(View(productForm)); }
public async Task <IActionResult> Create(ProductFormModel model) { if (!ModelState.IsValid) { model.Producers = await this.GetProducersItems(); model.Categories = await this.GetCategoriesItems(); return(View(model)); } await this.products.Create(model.Name, model.Code, model.Weight, model.Price, model.Description, model.ImageUrl, model.ProducerId, model.CategoryId); TempData.AddSuccessMessage($"Product {model.Name} created successfully."); return(RedirectToAction(nameof(All))); }
public async Task <IActionResult> Create(ProductFormModel model) { if (!ModelState.IsValid) { model.Brands = await this.dropDownService.GetBrandsAsync(); model.Categories = await this.dropDownService.GetCategoriesAsync(); return(View(model)); } var id = await this.products.CreateAndGetIdAsync(model); TempData.AddSuccessMessage($"Product '{model.Name}' created successfully!"); return(RedirectToDetails(id)); }
public ActionResult Edit(int id) { var product = _context.Products.SingleOrDefault(p => p.Id == id); if (product == null) { return(HttpNotFound()); } var viewModel = new ProductFormModel { Product = product, Header = "Edytuj produkt" }; return(View("ProductForm", viewModel)); }
public IActionResult Save(ProductFormModel formModel) { var _validator = new ProductValidator(_productService); var results = _validator.Validate(formModel); if (results.Errors.Any()) { foreach (var error in results.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } } if (ModelState.IsValid) { try { var product = (formModel.ProductId == AppStrings.NotSet) ? // Map form model to new entity _mapper.Map <Product>(formModel) : // Map form model to existing entity _mapper.Map <ProductFormModel, Product>(formModel, _productService.GetProduct(formModel.ProductId)); _productService.SaveProduct(product); TempData["SuccessMessage"] = AppStrings.ProductEditSuccessMessage; return(RedirectToAction(nameof(Details), new { id = product.ProductId })); } catch (ProductSpecException ex) { TempData["ErrorMessage"] = ex.Message; } catch (Exception ex) { _logger.LogMessage(ex.Message); TempData["ErrorMessage"] = AppStrings.GenericErrorMsg; } } formModel.ProductModelSelectItems = _productService.GetAllProductModels() .Select(x => new SelectListItem { Value = x.ProductModelId.ToString(), Text = x.Name }); return(View("ProductForm", formModel)); }
public async Task <IActionResult> Edit(int id, ProductFormModel model) { if (!ModelState.IsValid) { return(BadRequest()); } var productExist = await this.products.IsExist(id); if (!productExist) { return(NotFound()); } await this.products.Edit(id, model.Name, model.Code, model.Weight, model.Price, model.Description, model.ImageUrl, model.ProducerId, model.CategoryId); return(RedirectToAction(nameof(All))); }
public async Task <IActionResult> Edit(int id, ProductFormModel model) { if (!this.ModelState.IsValid) { return(View(model)); } var isEdited = await this.products.EditAsync(id, model); if (!isEdited) { return(BadRequest()); } TempData.AddSuccessMessage($"Product '{model.Name}' edited successfully!"); return(this.RedirectToPage("/Products/Details", new { id })); }
public ActionResult Edit(ProductFormModel productToEdit, bool continueEditing) { if (ModelState.IsValid) { //Mapping to domain Product product = Mapper.Map <ProductFormModel, Product>(productToEdit); product.Slug = StringConvert.ConvertShortName(product.Name) + "-" + product.Id; //this funcion not update all relationship value. _productService.EditProduct(product); //update attribute //foreach (var mapping in product.ProductAttributeMappings) //{ // _productAttributeMappingService.EditProductAttributeMapping(mapping); //} //update productpicture URL foreach (var picture in product.ProductPictureMappings) { _productPictureMappingService.EditProductPictureMapping(picture); _pictureService.EditPicture(picture.Picture); } //add tour relation #region [add tour relation] //var listProductRelation = _productRelationShipService.GetProductById(product.Id); //var item1 = listProductRelation.ToList()[0]; //var item2 = listProductRelation.ToList()[1]; //var item3 = listProductRelation.ToList()[2]; //item1.ProductRelateId = productToEdit.Id1; //item2.ProductRelateId = productToEdit.Id2; //item3.ProductRelateId = productToEdit.Id3; //_productRelationShipService.EditProductRelationship(item1); //_productRelationShipService.EditProductRelationship(item2); //_productRelationShipService.EditProductRelationship(item3); #endregion return(continueEditing ? RedirectToAction("Edit", "Product", new { productId = product.Id }) : RedirectToAction("Index", "Product")); } else { var listProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1); productToEdit.ListProductCategory = listProductCategory; return(View("Edit", productToEdit)); } }
public ActionResult Recommend(ProductFormModel form) { if (ModelState.IsValid) { var product = _productService.GetProduct(form.ID); product.ProductName = form.ProductName; product.CatId = form.CatId; product.Price = form.Price; product.AmountSales = form.AmountSales; product.IsRecommend = true; _productService.Recommend(product); Success("操作成功!"); } ViewBag.ProductCats = GetProductCats(); return(View("Recommend", form)); }
public async Task <IActionResult> Details(int id) { var currentProduct = await productService.GetProductByIdAsync(id); if (currentProduct == null) { return(NotFound()); } var model = new ProductFormModel { Id = currentProduct.Id, Name = currentProduct.Name, Description = currentProduct.Description, Pictures = currentProduct.Pictures }; return(View(model)); }
public async Task <bool> EditAsync(int id, ProductFormModel model) { var product = await this.products.GetByIdAsync(id); if (product == null) { return(false); } product.Name = model.Name; product.ImageURL = model.ImageUrl; product.BrandId = model.BrandId; product.CategoryId = model.CategoryId; product.Price = model.Price; product.Description = model.Description; await this.Context.SaveChangesAsync(); return(true); }