Пример #1
0
 public ActionResult TourEdit(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("TourEdit", "Product", new { productId = product.Id })
               : RedirectToAction("Tour", "Product"));
     }
     else
     {
         var listProductCategory = _productCategoryService.GetProductCategories().Where(c => c.Name.Contains("Tour")).ToSelectListItems(-1);
         productToEdit.ListProductCategory = listProductCategory;
         return(View("TourEdit", productToEdit));
     }
 }
 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 }));
     }
 }