public ViewResult List(string category, int page = 1) { var allproduct = repository.Products; var productModel = allproduct.Select(p => new Models.Product { ProductID = p.ProductID, Category = p.Category, Description = p.Description, Name = p.Name, Price = p.Price }).ToList(); var model = new ProductIndexModel() { Products = productModel.Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null? repository.Products.Count() : repository.Products.Where(e => e.Category == category).Count() }, CurrentCategory = category }; return(View(model)); }
// GET: Products public ActionResult Index(int?page, int?selectedCategory, string search = "") { var model = new ProductIndexModel { CategorySelectList = new CategoriesController().GetCategorySelectLists(selectedCategory), SelectedCategory = selectedCategory, Search = search }; if (selectedCategory == null) { model.ProductTabelList = db.Product.Include(p => p.Category) .Where(x => x.ProductKey.StartsWith(search)) .ToList() .ToPagedList(page ?? 1, Pagenumber.MaxResults); } else { //Get all possible subcategories var selectedCategoryIds = GetAllSubCategorieIds((int)selectedCategory); //Get all products with one of the selected categorie ids selectedCategoryIds.Add((int)selectedCategory); model.ProductTabelList = db.Product.Where(p => selectedCategoryIds.Contains(p.CategoryID) && p.ProductKey.StartsWith(search)) .ToList() .ToPagedList(page ?? 1, Pagenumber.MaxResults); } return(View(model)); }
public IActionResult Index() { IEnumerable <ProductListingModel> products = _productService.GetAll().Select(product => new ProductListingModel { Id = product.Id, Name = product.Name, ImageURL = product.ImageURL, Price = product.Price, Type = product.Type, Style = product.Style, Country = product.Country, City = product.City, Adress = product.Adress, Date = product.Date, Time = product.Time, Age = product.Age, Accepted = product.Accepted }); ProductIndexModel model = new ProductIndexModel { ProductList = products }; return(View(model)); }
public IActionResult Index() { ViewBag.CategorySelectList = new SelectList(_context.GetAllCategory().Select(o => o.CategoryKind), "CategoryKind"); var products = _context.GetAll(); var resultList = products .Select(result => new ProductIndexListingModel { Id = result.Id, ItemName = result.ItemName, Description = result.Description, Price = result.Price.ToString(), UploadTime = result.UploadTime.ToString(), Category = result.Category.CategoryKind, PersonName = result.Person.PersonName, PersonEmail = result.Person.Email }); var model = new ProductIndexModel() { Products = resultList }; return(View(model)); }
public IActionResult Index() { var list1 = _IProductService.getAll(). Select(p => new ProductListingModel { Id = p.Id, Name = p.Name, Description = p.Description, Price = p.Price, Picture = p.Picture }); var list2 = _ICategoryService.getAll() .Select(c => new ProductCategoryModel { CategoryId = c.CategoryId, Name = c.Name }); var model = new ProductIndexModel { productIndexModels = list1, CategoryIndexModels = list2 }; return(View(model)); }
public IActionResult GetProducts() { var tableModel = new DataTablesAjaxRequestModel(Request); var model = new ProductIndexModel(_configuration); var data = model.GetProducts(tableModel); return(Json(data)); }
//if action = 1 -> "confirm and pay" //if action = 2 -> packingNoteDetails //if action = 3 -> chyba INCOICE //if action = 4 -> worker, only view public IActionResult OrderSummary(int OrderId, int ActionId, int TempId) { ViewBag.ActionId = ActionId; ViewBag.Temp = TempId; Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine("ORderId " + OrderId); Console.WriteLine("Action " + ActionId); Console.WriteLine("Temp " + TempId); //OrderSummaryIndexListingModel var order = _order.GetOrder(OrderId); var orderLines = _order.GetAllLines(OrderId); var listingResult = orderLines .Select(item => new ProductIndexListingModel { Id = item.Product.Id, Color = item.Product.Color, Height = item.Product.Height, Name = item.Product.Name, Price = item.Product.Price, ProductNumber = item.Product.ProductNumber, Purpose = item.Product.Purpose, Shape = item.Product.Shape, Size = item.Product.Size, Width = item.Product.Width }); var model = new ProductIndexModel() { Products = listingResult }; OrderSummaryIndexListingModel model1 = new OrderSummaryIndexListingModel() { AddressId = order.Address.Id, AppartmentNumber = order.Address.AppartmentNumber, City = order.Address.City, Country = order.Address.Country, PostCode = order.Address.PostCode, Street = order.Address.Street, StreetNumber = order.Address.StreetNumber, ClientId = order.Client.Id, ClientNumber = order.Client.ClientNumber, Name = order.Client.Name, Surname = order.Client.Surname, PhoneNumer = order.Client.PhoneNumer, email = order.Client.email, Products = listingResult, OrderId = order.Id, OrderNumber = order.OrderNumber, TotalPrice = order.TotalPrice }; return(View(model1)); }
public IActionResult IndexSearchAdmin(ProductIndexModel model) { return(RedirectToRoute(new { controller = "Database", action = "IndexAdmin", modelIndex = "", search = model.SearchString, })); }
public IActionResult AddNewProduct() { ProductIndexModel model = new ProductIndexModel { ProductInputModel = new ProductInputModel(), ProductCategories = this.shopDbUsageService.ExtractAllCategoriesNames(), }; return(this.View(model)); }
public IActionResult Index(int?descr, string name, int page = 1, SortState sortOrder = SortState.NameAsc) { IEnumerable <ProductListingModel> products = _productService.GetAll().Select(product => new ProductListingModel { Id = product.Id, Description = product.Description, Name = product.Name, ImageURL = product.ImageURL, Price = product.Price }); if (descr != null && descr != 0) { products = products.Where(p => p.Id == descr); } if (name != null) { products = products.Where(p => p.Name.Contains(name)); } switch (sortOrder) { case SortState.NameDesc: products = products.OrderByDescending(s => s.Name); break; case SortState.PriceAsc: products = products.OrderBy(s => s.Price); break; case SortState.PriceDesc: products = products.OrderByDescending(s => s.Price); break; default: products = products.OrderBy(s => s.Name); break; } int pageSize = 8; var count = products.Count(); var items = products.Skip((page - 1) * pageSize).Take(pageSize).ToList(); //PageViewModal pageViewModel = new PageViewModal(count, page, pageSize); ProductIndexModel model = new ProductIndexModel { PageViewModel = new PageViewModal(count, page, pageSize), SortViewModel = new SortViewModel(sortOrder), FilterViewModel = new FilterViewModel(products.ToList(), descr, name), ProductList = items.AsEnumerable() }; return(View(model)); }
public ActionResult Index(string id) { var model = new ProductIndexModel(); using (var repos = new ProductRepository()) { model.Products = id == null || id.Length > 2? repos.GetAll() : repos.GetAll(Convert.ToInt32(id.Substring(0, 2)), Convert.ToInt32(id.Substring(2, id.Length - 2))); } return(View(model)); }
public IActionResult Index() { var model = new ProductIndexModel { Products = _context.Products .Include(x => x.Tasks) .ThenInclude(x => x.Status) .ToList() }; return(View(model)); }
public IActionResult Index() { // get all products from repository var allProductsFromRepository = _productRepository.GetAll(); var model = new ProductIndexModel(); // read the cookie if (Request.Cookies["products"] != null) { // split the cookie value into string ids var cookieValueArray = Request.Cookies["products"].ToString().Split("_"); // parse cookie strings into Guids (for better performance during the comparision below) List <Guid> cookieValues = new List <Guid>(); foreach (string s in cookieValueArray) { cookieValues.Add(Guid.Parse(s)); } // Get a list of all products in cart List <ProductDetailModel> productDetailModels = new List <ProductDetailModel>(); foreach (Guid g in cookieValues) { foreach (Product p in allProductsFromRepository) { if (g == p.Id) { ProductDetailModel pdm = new ProductDetailModel() { Id = p.Id, Name = p.Name, ImageUrl = p.ImageUrl, Price = p.Price, TypeOfProduct = p.TypeOfProduct }; productDetailModels.Add(pdm); break; } } } model.Products = productDetailModels; return(View(model)); } // if there is no cookie (nothing in cart) return an empty model return(View(model)); }
public async Task <IActionResult> Index() { var products = await _service.GetProducts(); var categories = await _categoryService.GetCategories(); var model = new ProductIndexModel() { Products = _mapper.Map <List <ProductViewModel> >(products), Categories = _mapper.Map <List <CategoryViewModel> >(categories) }; return(View(model)); }
public IActionResult Product() { var productList = _context.Products .Select(product => new ProductListingModel { Id = product.Id, ProductName = product.ProductName }); var model = new ProductIndexModel { ProductList = productList }; return(View(model)); }
public async Task <IActionResult> AddNewProduct(ProductIndexModel model) { if (this.ModelState.IsValid) { Tuple <string, string> tuple = await this.shopDbUsageService.AddProduct(model.ProductInputModel); this.TempData[tuple.Item1] = tuple.Item2; } else { this.TempData["Error"] = ErrorMessages.InvalidInputModel; } return(this.RedirectToAction("AddNewProduct", "Shop")); }
public ActionResult DeleteProduct(Guid id, ProductIndexModel indexModel) { var response = ServiceHelper.Product.ExecuteDispose(s => s.DeleteProduct(id, PhysicalDataImagesFolderPath)); if (response.Success) { indexModel.Pagination.CurrentPageIndex = 1; PopulateIndexModel(indexModel); return JsonObject(true, BackendMessage.DeleteSuccessfull, new { html = PartialViewToString("_list", indexModel) }); } return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes()); }
public IActionResult Index() { var productModels = _products.GetAllProducts(); var listingResult = productModels .Select(result => new ProductIndexListingModel { Id = result.Id, Title = result.Title, Price = result.Price //CategoryId = _products.GetCategoryId(result.Id) }); var model = new ProductIndexModel() { Products = listingResult }; return(View(model)); }
public async Task <IActionResult> Index(int id) { var products = await _productRepository.All(); var max = (int)Math.Ceiling(products.Count() / 9.0); id = id <0 ? 0 : id> max ? max : id; var model = new ProductIndexModel { Products = products.Skip((id - 1) * 9).Take(9).Select(_ => new ProductModel { Id = _.Id, Name = _.Name, Price = _.Price }).ToList() }; ViewBag.Id = id; return(View(model)); }
public IActionResult Lollies() { var allLollies = _productRepository.GetAllLollies(); var productIndexModels = allLollies.Select(result => new ProductDetailModel { Id = result.Id, Name = result.Name, Price = result.Price, ImageUrl = result.ImageUrl }).ToList(); var model = new ProductIndexModel() { Products = productIndexModels }; return(View(model)); }
public IActionResult IndexNewAdmin(ProductIndexModel model) { string index = ""; foreach (WinkelItem modelWinkelItem in model.WinkelItems) { if (modelWinkelItem.Selected) { index += modelWinkelItem.Name + "/"; } } return(RedirectToRoute(new { controller = "Database", action = "IndexAdmin", modelIndex = index, })); }
/** * The Customer can browse the entire list of fruit products * */ public IActionResult Index(int page = 1, string name = null, string price = null) { var allproduct = repository.Products; var productModel = allproduct.Select(p => new Product { ID = p.ID, Name = p.Name, pricePerUnit = p.pricePerUnit }).ToList(); var model = new ProductIndexModel() { Products = productModel .OrderBy(p => p.ID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = repository.Products.Count() }, }; if (name != null) { model.Products = model.Products.OrderByDescending(x => x.Name); } else if (price != null) { model.Products = model.Products.OrderByDescending(x => x.pricePerUnit); } else { model.Products = model.Products.OrderBy(x => x.Name); } return(View(model)); }
public ActionResult Products(int?page, int?selectedCategory, string search) { var model = new ProductIndexModel { CategorySelectList = new CategoriesController().GetCategorySelectLists(selectedCategory), SelectedCategory = selectedCategory }; if (selectedCategory == null) { if (search == null) { model.ProductTabelList = db.Product.Include(p => p.Category).Include(p => p.Manufacturer) .OrderBy(p => p.ProductKey) .ToList() .ToPagedList(page ?? 1, Pagenumber.MaxResults); } else { model.ProductTabelList = db.Product.Include(p => p.Category).Include(p => p.Manufacturer) .Where(x => x.ProductKey.StartsWith(search)) .OrderBy(p => p.ProductKey) .ToList() .ToPagedList(page ?? 1, Pagenumber.MaxResults); } } else { var selectedCategoryIds = GetAllSubCategorieIds(selectedCategory); selectedCategoryIds.Add(selectedCategory); model.ProductTabelList = db.Product.Where(p => selectedCategoryIds.Contains(p.CategoryID)).Include(p => p.Manufacturer) .OrderBy(p => p.ProductKey) .ToList() .ToPagedList(page ?? 1, Pagenumber.MaxResults); } return(View(model)); }
public ViewResult Index(int p = 1, int c = 0) { int _skip = (p - 1) * pageSize; List <Product> _products = c == 0 ? productManager.GetAll() : productManager.GetByCatID(c); List <Category> _categories = categoryManager.GetAll(); ProductIndexModel model = new ProductIndexModel() { products = _products.Skip(_skip).Take(pageSize).ToList(), categories = _categories, currentCategoryName = _categories.Where(w => w.CategoryID == c).Select(s => s.CategoryName).FirstOrDefault(), PagingInfo = new PagingInfo() { currentPage = p, totalProductCount = _products.Count(), pageSize = pageSize, currentCategory = c } }; return(View(model)); }
public IActionResult Index() //map every element of collection in product models { var productModel = _product.GetAll(); var listingResult = productModel .Select(result => new ProductListingModel { Id = result.ProductID, Category = result.ProductCategory, Name = result.ProductName, State = result.ProductState, Company = _product.GetCurrentComapny(result.ProductID), Owner = _product.GetCurrentOwner(result.ProductID) }); var model = new ProductIndexModel() { Products = listingResult }; return(View(model)); }
public PartialViewResult UpdateProductIndex(int selectedCategory, string search = "") { // Create model and add the tabel data var catController = new CategoriesController(); var model = new ProductIndexModel { SelectedCategory = selectedCategory, CategorySelectList = catController.GetCategorySelectLists(selectedCategory), Search = search }; //Get all possible subcategories var selectedCategoryIds = GetAllSubCategorieIds(selectedCategory); selectedCategoryIds.Add(selectedCategory); //Get all products with one of the selected categorie ids model.ProductTabelList = db.Product.Where(p => selectedCategoryIds.Contains(p.CategoryID) && p.ProductKey.StartsWith(search)) .ToList() .ToPagedList(1, Pagenumber.MaxResults); return(PartialView("_productIndex", model)); }
public async Task <IActionResult> Index() { Checker.CheckLangId(HttpContext, db, "adminLangId").Wait(); HttpContext.SetCurrentPage("Index", "Product"); int langId = HttpContext.GetLanguage("adminLangId"); List <ProductLanguage> productLanguages = await db.ProductLanguages.Where(pl => pl.LanguageId == langId) .Include(p => p.Product) .ThenInclude(p => p.ProductPhotos) .ToListAsync(); List <SubcategoryLanguage> subcategoryLanguages = await db.SubcategoryLanguages.Where(sl => sl.LanguageId == langId).Include(s => s.Subcategory).ToListAsync(); ProductIndexModel model = new ProductIndexModel { ProductLanguages = productLanguages, SubcategoryLanguages = subcategoryLanguages }; return(View(model)); }
public ActionResult DeleteImage(Guid id, Guid productId, ProductIndexModel indexModel) { var response = ServiceHelper.Product.ExecuteDispose(s => s.DeleteImage(id, PhysicalDataImagesFolderPath)); if (response.Success) { var product = ServiceHelper.Product.ExecuteDispose(s => s.GetProduct(productId)); if (product == null) { return JsonObject(false, BackendMessage.CannotLoadData); } PopulateIndexModel(indexModel); return JsonObject(true, BackendMessage.DeleteSuccessfull, new { productList = PartialViewToString("_list", indexModel), imageList = PartialViewToString("ImageList/_productImageList", product.Map<Product, ProductModel>()) }); } return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes()); }
public ActionResult ExportProducts(ProductIndexModel model) { model.IsExport = true; PopulateIndexModel(model); var name = "Products"; var ef = new ExcelFile(); var ws = ef.Worksheets.Add(name); var ri = 0; var ci = 0; Action<ExcelCell> fontmatCaption = cell => { cell.Style.Font.Weight = ExcelFont.BoldWeight; cell.Style.VerticalAlignment = VerticalAlignmentStyle.Top; }; #region header ws.Cells[ri, ci].Value = "CategoryCode"; fontmatCaption(ws.Cells[ri, ci]); ++ci; ws.Cells[ri, ci].Value = "ProductCode"; fontmatCaption(ws.Cells[ri, ci]); ++ci; ws.Cells[ri, ci].Value = "UnitCode"; fontmatCaption(ws.Cells[ri, ci]); ++ci; ws.Cells[ri, ci].Value = "Status"; fontmatCaption(ws.Cells[ri, ci]); ++ci; ws.Cells[ri, ci].Value = "Cost"; fontmatCaption(ws.Cells[ri, ci]); ++ci; ws.Cells[ri, ci].Value = "Vat"; fontmatCaption(ws.Cells[ri, ci]); ++ci; ws.Cells[ri, ci].Value = "Name"; fontmatCaption(ws.Cells[ri, ci]); ++ci; ws.Cells[ri, ci].Value = "Price"; fontmatCaption(ws.Cells[ri, ci]); #endregion #region body var cache = ObjectFactory.GetInstance<ICacheHelper>(); foreach (var item in model.Results) { ++ri; ci = 0; var category = cache.GetCategory(item.CategoryId); var unit = ""; if (item.UnitId!=null) { unit = cache.GetCategory(Guid.Parse(item.UnitId.ToString())).Code; } ws.Cells[ri, ci++].Value = category.Code; ws.Cells[ri, ci++].Value = item.ProductCode; ws.Cells[ri, ci++].Value = unit; ws.Cells[ri, ci++].Value = item.Status; ws.Cells[ri, ci++].Value = item.Cost; ws.Cells[ri, ci++].Value = item.Vat; ws.Cells[ri, ci++].Value = item.Name; ws.Cells[ri, ci++].Value = item.Price; } #endregion var cd = new System.Net.Mime.ContentDisposition { FileName = name + ".xls", // always prompt the user for downloading, set to true if you want // the browser to try to show the file inline Inline = false, }; Response.AppendHeader("Content-Disposition", cd.ToString()); var memoryStream = new MemoryStream(); ef.SaveXls(memoryStream); memoryStream.Position = 0; return File(memoryStream, "application/ms-excel"); }
// test method, not required public IActionResult RemoveFromCart(Guid id) { var model = new ProductIndexModel(); return(View(model)); }
public IActionResult Find(ProductIndexModel model) { return(View(model)); }
public IActionResult IndexAdmin(string modelIndex, string search, int id) { ProductIndexModel model; if (id != 0) { model = new ProductIndexModel { Allergies = _manager.GetAllergies().ToList(), Products = new List <Product>(), WinkelItems = new List <WinkelItem>() }; model.Products.Add(_manager.GetProduct(id)); foreach (Allergie allergie in _manager.GetAllergies().ToList()) { model.WinkelItems.Add(new WinkelItem { Id = allergie.AllergieId, Name = allergie.Naam }); } } else { if (search != null) { IList <Product> products = new List <Product>(); IList <Allergie> allergies = _manager.GetAllergies().ToList(); foreach (Product product in _manager.GetProducts().ToList()) { if (RemoveDiacritics(product.Naam.ToLower()).Contains(RemoveDiacritics(search.ToLower()))) { products.Add(product); } } model = new ProductIndexModel { Allergies = allergies, Products = products, WinkelItems = new List <WinkelItem>() }; foreach (Allergie allergie in allergies) { model.WinkelItems.Add(new WinkelItem { Id = allergie.AllergieId, Name = allergie.Naam }); } } else { if (modelIndex != null) { model = new ProductIndexModel(); if (modelIndex.Length > 0) { IList <Product> products = new List <Product>(); IList <Allergie> allergies = _manager.GetAllergies().ToList(); IList <String> strings = modelIndex.Split("/").ToList(); foreach (string modelIndexWinkelItem in strings) { foreach (Product product in _manager.GetProducts().ToList()) { if (product.ProductAllergies.Find(x => x.Allergie.Naam == modelIndexWinkelItem) != null) { products.Add(product); } } } model = new ProductIndexModel { Allergies = allergies, Products = products, WinkelItems = new List <WinkelItem>() }; foreach (Allergie allergie in allergies) { model.WinkelItems.Add(new WinkelItem { Id = allergie.AllergieId, Name = allergie.Naam, Selected = modelIndex.Contains(allergie.Naam) ? true : false }); } } } else { IList <Product> products = _manager.GetProducts().ToList(); IList <Allergie> allergies = _manager.GetAllergies().ToList(); model = new ProductIndexModel { Allergies = allergies, Products = products, WinkelItems = new List <WinkelItem>() }; foreach (Allergie allergie in allergies) { model.WinkelItems.Add(new WinkelItem { Id = allergie.AllergieId, Name = allergie.Naam }); } } } } return(View(model)); }
public IActionResult Index() { var model = new ProductIndexModel(_configuration); return(View(model)); }
private void PopulateIndexModel(ProductIndexModel model) { model.InitSortInfo(); if (string.IsNullOrWhiteSpace(model.SortBy)) { model.SortBy = "Name"; } var filter = new FindRequest { TextSearch = model.TextSearch, SortOption = new SortOption(new[] { new SortItem(model.SortBy, model.SortDirection.Value) }), PageOption = new PageOption { PageSize = model.Pagination.PageSize, PageNumber = model.Pagination.CurrentPageIndex } }; var response = ServiceHelper.Product.ExecuteDispose(s => s.FindProducts(filter)); model.Results = response.Results.MapList<ProductModel>(); model.Pagination.TotalRecords = response.TotalRecords; }
public ActionResult GetListProduct(ProductIndexModel model) { PopulateIndexModel(model); return JsonObject(true, string.Empty, new { html = PartialViewToString("_list", model) }); }
public ActionResult SaveProduct(ProductModel model) { if (model.IsNew && !CanAdd) { return GetAddDeniedResult(); } if (!model.IsNew && !CanUpdate) { return GetUpdateDeniedResult(); } if (!ModelState.IsValid && GetModelStateErrorList().Any()) { return JsonObject(false, GetModelStateErrors()); } #region save list image var listImagePath = new List<string>(); for (var i = 0; i < Request.Files.Count; ++i) { var file = Request.Files[i]; if (file != null && !string.IsNullOrWhiteSpace(file.FileName)) { var extension = Path.GetExtension(file.FileName).ToStr(); if (!SiteUtils.IsImageFile(file.FileName)) { return JsonObject(false, BackendMessage.FileTypeIsInvalid); } if (!SiteUtils.ImageSizeIsValid(file.ContentLength)) { return JsonObject(false, BackendMessage.FileMaxSize5MB); } var imagePath = Guid.NewGuid() + extension; listImagePath.Add(imagePath); var filePath = PhysicalDataFilePath(imagePath); file.SaveAs(filePath); } } #endregion var entity = model.Map<ProductModel, Product>(); if (entity.IsNew) { entity.InitId(); entity.CreatedDate = DateTime.UtcNow; entity.UpdateDate = DateTime.UtcNow; } else { var oldData = ServiceHelper.Product.ExecuteDispose(s => s.GetProduct(entity.Id)); if (oldData == null) { return JsonObject(false, BackendMessage.CannotLoadData); } entity.CreatedDate = oldData.CreatedDate; entity.UpdateDate = DateTime.UtcNow; } var response = ServiceHelper.Product.ExecuteDispose(s => s.SaveProduct(new SaveRequest { Entity = entity })); if (response.Success) { if (listImagePath.Any()) { var listImages = new List<ProductImage>(); listImagePath.ForEach(imagePath => { var image = new ProductImage { ImagePath = imagePath, ProductId = entity.Id, CreatedDate = DateTime.UtcNow, Visible = true }; image.InitId(); listImages.Add(image); }); ServiceHelper.Product.ExecuteDispose(s => s.SaveListImage(listImages)); } var indexModel = new ProductIndexModel { TextSearch = model.TextSearch, }; PopulateIndexModel(indexModel); return JsonObject(true, BackendMessage.SaveDataSuccess, new { html = PartialViewToString("_list", indexModel) }); } if (listImagePath.Any()) { listImagePath.ForEach(DeleteImageFile); } return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes()); }
public ActionResult SaveImage(Guid productId, bool? visible, string textSearch) { var imagePath = string.Empty; #region save image if (Request.Files["fileImage"] != null && !string.IsNullOrWhiteSpace(Request.Files["fileImage"].FileName)) { var file = Request.Files["fileImage"]; var extension = Path.GetExtension(file.FileName).ToStr(); if (!SiteUtils.IsImageFile(file.FileName)) { return JsonObject(false, BackendMessage.FileTypeIsInvalid); } if (!SiteUtils.ImageSizeIsValid(file.ContentLength)) { return JsonObject(false, BackendMessage.FileMaxSize5MB); } imagePath = Guid.NewGuid() + extension; var filePath = PhysicalDataFilePath(imagePath); file.SaveAs(filePath); } #endregion var productImage = new ProductImage { ImagePath = imagePath, ProductId = productId, CreatedDate = DateTime.UtcNow, Visible = (visible==null)?false:true }; productImage.InitId(); var response = ServiceHelper.Product.ExecuteDispose(s => s.SaveImage(productImage)); if (response.Success) { var product = ServiceHelper.Product.ExecuteDispose(s => s.GetProduct(productId)); if (product == null) { return JsonObject(false, BackendMessage.CannotLoadData); } var indexModel = new ProductIndexModel { TextSearch = textSearch }; PopulateIndexModel(indexModel); return JsonObject(true, BackendMessage.SaveDataSuccess, new { productList = PartialViewToString("_list", indexModel), imageList = PartialViewToString("ImageList/_productImageList", product.Map<Product, ProductModel>()) }); } return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes()); }
public ActionResult Index(ProductIndexModel model) { PopulateIndexModel(model); return View(model); }