public ProductFormVM GetProduct(int id) { ProductFormVM vm = new ProductFormVM(); using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <Product>(); vm.Product = rep.GetById(id); var repCategory = ctx.GetRepository <Category>(); vm.Categories = repCategory.Get().ToList(); var repProductCategory = ctx.GetRepository <ProductCategory>(); IList <ProductCategory> productCategoryList = repProductCategory.Find("WHERE PRODUCTID = " + id).ToList(); if (productCategoryList != null && productCategoryList.Count > 0) { string whereProductCategoryList = string.Join(",", productCategoryList.Select(a => a.CategoryId).ToArray()); vm.SelectedCategories = ctx.GetRepository <Category>().Find("WHERE ID in (" + whereProductCategoryList + ")").ToList(); } var repProductColor = ctx.GetRepository <ProductColor>(); IList <ProductColor> productColorList = repProductColor.Find("WHERE PRODUCTID = " + id).ToList(); if (productColorList != null && productColorList.Count > 0) { string whereProductColorList = string.Join(",", productColorList.Select(a => a.ColorId).ToArray()); vm.Colors = ctx.GetRepository <Color>().Find("WHERE ID in (" + whereProductColorList + ")").ToList(); } } return(vm); }
public IActionResult Edit(int Id) { ProductFormVM model = new ProductFormVM(); model.Product = productOperations.GetEditProductData(Id); return(View(model)); }
public IActionResult Add(ProductFormVM model) { if (!ModelState.IsValid) { return(View(model)); } model.Product.Thumb = UploadFile(model.Product.file); productOperations.Create(model.Product); return(RedirectToAction(nameof(ProductList))); }
public ActionResult Edit(int itemId = -1) { ProductFormVM vm = new ProductFormVM(); vm.Product = new Product() { Id = itemId, ModuleId = CurrentModuleId }; return(View(vm)); }
public HttpResponseMessage Get(int id) { var vm = new ProductFormVM(); if (id > 0) { vm = ProductDataManager.Instance.GetProduct(id); } return(Request.CreateResponse(HttpStatusCode.OK, vm)); }
public IActionResult Edit(ProductFormVM model) { if (!ModelState.IsValid) { return(View(model)); } string thumb = UploadFile(model.Product.file); model.Product.Thumb = string.IsNullOrEmpty(thumb) ? model.Product.Thumb : thumb; productOperations.Edit(model.Product); return(View(model)); }
public HttpResponseMessage Put(ProductFormVM vm) { // same Post if (vm.Product.Id > 0) { ProductDataManager.Instance.Update(vm.Product); foreach (var cate in vm.SelectedCategories) { if (cate.Id <= 0 || cate.IsDirty == null) { // add new ProductDataManager.Instance.CreateProductCategory(new ProductCategory() { ProductId = vm.Product.Id, CategoryId = cate.Id }); } else if (cate.IsDirty != null && cate.IsDirty.Value) { // remove uncheck ProductDataManager.Instance.DeleteProductCategory(new ProductCategory() { ProductId = vm.Product.Id, CategoryId = cate.Id }); } } foreach (var col in vm.Colors) { if (col.Id <= 0) { ColorDataManager.Instance.Create(col); var newColor = ColorDataManager.Instance.GetNewItem(); ProductDataManager.Instance.CreateProductColor(new ProductColor() { ProductId = vm.Product.Id, ColorId = newColor.Id }); } else { ColorDataManager.Instance.Update(col); } } } return(Request.CreateResponse(HttpStatusCode.OK)); }
public IActionResult Add() { ProductFormVM model = new ProductFormVM(); return(View(model)); }