public ActionResult Edit(string id ) { var product = ProductRepository.GetSingleProduct(new Guid(id)); var article = ProductRepository.GetArticleByProduct(id); var properties = ProductRepository.GetPropertiesOfProduct(id); var model = new ProductEditViewModel() { Article = article != null ? article.Content : "", ArticleDescription = article != null ? article.ArticleDescription : "", Available = product.Available, CategoryId = product.CategoryId, Class = product.Class, Color = string.Join(",", product.Color.ToArray()), CurrentPriceVnd = product.CurrentPriceVnd, CurrentPriceUsd = product.CurrentPriceUsd, Manufacturer = product.Manufacturer, Name = product.Name, Permalink = product.Permalink, ProductId = product.ProductId, Size = string.Join(",", product.Size), Supplier = product.Supplier, Unit = product.Unit, UnitWeight = product.UnitWeight, Weight = product.Weight, Properties = properties, ProductCode = product.ProductCode, CreateBy = product.CreateBy, UpdateBy = product.UpdateBy }; return View(model); }
public ActionResult Edit(ProductEditViewModel model) { var result = ProductRepository.UpdateProduct(model.ProductId, model.CategoryId,model.ProductCode, model.Name, model.Color, model.Size, model.Weight, model.UnitWeight, model.Class, model.CurrentPriceVnd, model.CurrentPriceUsd, model.Unit, model.Manufacturer, model.Supplier, model.Available, model.Properties, SessionManager.Admin.UserId); if (result.Result) { var article = ProductRepository.EditArticleOfProduct(model.Name, model.ArticleDescription, model.ProductId, model.Article, true, SessionManager.Admin.UserId); if (article.Result) return RedirectToAction("index", "productmanagement", new {area = "manager"}); ModelState.AddModelError("",article.Message); } ModelState.AddModelError("",result.Message); return View(model); }
public ActionResult InsertProduct(string categoryChildId, string categoryParentId) { var id = categoryChildId ?? categoryParentId; var category = ProductRepository.GetCategoryById(id); var product = new ProductEditViewModel { Properties = category.Properties.MapTo<PropertyModel>(), CategoryId = category.CategoryId }; return View("~/Areas/Manager/Views/ProductManagement/Insert.cshtml",product); }
public ActionResult Insert(ProductEditViewModel model) { var photos = new List<ProductPhotoEditModel>(); if (model.Photo!= null && model.Photo.Any()) { foreach (var photo in model.Photo) { if (photo.ContentType.Contains("image")) { var ms = new MemoryStream(); photo.InputStream.CopyTo(ms); photos.Add(new ProductPhotoEditModel() { FileContent = Convert.ToBase64String(ms.ToArray()), FileName = photo.FileName, FileType = photo.ContentType }); } } } var result = ProductRepository.InsertProduct(model.CategoryId,model.ProductCode, photos, model.Name, model.Color, model.Size, model.Weight, model.UnitWeight, model.Class, model.CurrentPriceVnd, model.CurrentPriceUsd, model.Unit, model.Manufacturer, model.Supplier, model.Available, model.Properties, SessionManager.Admin.UserId); if (result.Result) { var article = ProductRepository.InsertArticle(model.Name, model.ArticleDescription, new Guid(result.Message), model.Article, true, SessionManager.Admin.UserId); if (article.Result) { return RedirectToAction("index", "productmanagement"); } ModelState.AddModelError("", article.Message); } ModelState.AddModelError("",result.Message ); return View("~/Areas/Manager/Views/ProductManagement/Insert.cshtml", model); }