public SetMenuImportResultModels ExtendCategories(InteCategoriesViewModels model, ref string msg) { SetMenuImportResultModels importItems = new SetMenuImportResultModels(); try { InteCategoriesApiModels paraBody = new InteCategoriesApiModels(); paraBody.AppKey = Commons.AppKey; paraBody.AppSecret = Commons.AppSecret; paraBody.CreatedUser = Commons.CreateUser; paraBody.RegisterToken = new RegisterTokenModels(); paraBody.ListCategoryID = model.ListItem.Where(o => o.IsSelected).Select(s => s.ID).ToList(); paraBody.ListStoreIDExtendTo = model.StoreExtendTo; paraBody.StoreID = model.StoreExtendFrom; //==================== var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.CategoryExtend, null, paraBody); if (result != null) { dynamic data = result.Data; msg = data["Description"]; if (result.Success) { importItems.Name = "<strong style=\"color: #d9534f;\">" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(msg) + "<strong>"; } } } catch (Exception e) { _logger.Error("Categories_Extend: " + e); } return(importItems); }
public ActionResult Extend(InteCategoriesViewModels model) { try { if (string.IsNullOrEmpty(model.StoreExtendFrom)) { ModelState.AddModelError("StoreExtendFrom", CurrentUser.GetLanguageTextFromKey("Please choose store.")); } if (model.StoreExtendTo == null || model.StoreExtendTo.Count == 0) { ModelState.AddModelError("StoreExtendTo", CurrentUser.GetLanguageTextFromKey("Please choose store.")); } if (model.ListItem == null || model.ListItem.Count(x => x.IsSelected) == 0) { ModelState.AddModelError("ListItem", CurrentUser.GetLanguageTextFromKey("Please choose item.")); } // Return new ListStoreTo var lstStoreView = (List <StoreModels>)ViewBag.StoreID.Items; var temps = lstStoreView.Where(ww => ww.Id != model.StoreExtendFrom).ToList(); model.ListStoreTo = new SelectList(temps, "Id", "Name", "CompanyName", 1); if (!ModelState.IsValid) { return(View(model)); } //==================== SetMenuImportResultModels importModel = new SetMenuImportResultModels(); string msg = ""; importModel = _factory.ExtendCategories(model, ref msg); if (!string.IsNullOrEmpty(msg)) { return(View("ExtendDetail", importModel)); } else { ModelState.AddModelError("extend", msg); return(View(model)); } } catch (Exception ex) { _logger.Error("Categories_Extend: " + ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public ActionResult Import(SandboxImportModel model) { try { if (model.ListStores == null) { ModelState.AddModelError("ListStores", CurrentUser.GetLanguageTextFromKey("Please choose store")); return(View(model)); } //if (model.ImageZipUpload == null || model.ImageZipUpload.ContentLength <= 0) //{ // ModelState.AddModelError("ImageZipUpload", "Image Folder (.zip) cannot be null"); // return View(model); //} if (model.ImageZipUpload != null) { if (!Path.GetExtension(model.ImageZipUpload.FileName).ToLower().Equals(".zip")) { ModelState.AddModelError("ImageZipUpload", ""); return(View(model)); } } if (model.ExcelUpload == null || model.ExcelUpload.ContentLength <= 0) { ModelState.AddModelError("", CurrentUser.GetLanguageTextFromKey("Excel filename cannot be null")); return(View(model)); } FileInfo[] listFiles = new FileInfo[] { }; string serverZipExtractPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads") + "/ExtractFolder"; if (model.ImageZipUpload != null && model.ImageZipUpload.ContentLength > 0) { bool isFolderEmpty; string fileName = Path.GetFileName(model.ImageZipUpload.FileName); string filePath = string.Format("{0}/{1}", System.Web.HttpContext.Current.Server.MapPath("~/Uploads"), fileName); //upload file to server if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } model.ImageZipUpload.SaveAs(filePath); //extract file CommonHelper.ExtractZipFile(filePath, serverZipExtractPath); //delete zip file after extract if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } isFolderEmpty = CommonHelper.IsDirectoryEmpty(serverZipExtractPath); if (!isFolderEmpty) { string[] extensions = new[] { ".jpg", ".png", ".jpeg" }; DirectoryInfo dInfo = new DirectoryInfo(serverZipExtractPath); //Getting Text files listFiles = dInfo.EnumerateFiles() .Where(f => extensions.Contains(f.Extension.ToLower())) .ToArray(); } } SetMenuImportResultModels importModel = new SetMenuImportResultModels(); string msg = ""; // read excel file if (model.ExcelUpload != null && model.ExcelUpload.ContentLength > 0) { string fileName = Path.GetFileName(model.ExcelUpload.FileName); string filePath = string.Format("{0}/{1}", System.Web.HttpContext.Current.Server.MapPath("~/Uploads"), fileName); //Directory.CreateDirectory(filePath); //upload file to server if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } model.ExcelUpload.SaveAs(filePath); int totalRowExcel; importModel.ListImport = _factory.ImportModifier(filePath, listFiles, out totalRowExcel, model.ListStores, ref msg); importModel.TotalRowExcel = totalRowExcel; //delete folder extract after get file. if (System.IO.Directory.Exists(serverZipExtractPath)) { System.IO.Directory.Delete(serverZipExtractPath, true); } //delete file excel after insert to database if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } if (msg.Equals("")) { return(View("ImportDetail", importModel)); } else { _logger.Error("Product_Modifier_Import: " + msg); ModelState.AddModelError("ImageZipUpload", msg); return(View(model)); } } catch (Exception e) { _logger.Error("Product_Modifier_Import: " + e); ModelState.AddModelError("ImageZipUpload", string.Format(CurrentUser.GetLanguageTextFromKey("Import file have error").ToString() + ": {0}", e.Message)); return(View(model)); } }