public ActionResult UploadFiles(FormCollection collection) { ParamterFileModel model = new ParamterFileModel(); JsonResultInfo result = new JsonResultInfo(); this.TryUpdateModel(model); if (this.ModelState.IsValid) { List<UploadFileModel> uploadFiles = null; int index = 0; string fileName = string.Empty; for (index = 0; index < Request.Files.Count; index++) { fileName = Request.Files[index].FileName; if (string.IsNullOrEmpty(fileName) == false) { uploadFiles.Add(UploadFileHelper.Upload(Request.Files[index], "ParameterFileUploadPath", Request.Files[index].FileName)); } } return Json(new { Error = string.Empty, Files = uploadFiles }); } else { result.Errors = ValidationHelper.GetErrorInfo(ModelState); } return Json(result); }
public ActionResult Create(FormCollection collection) { ModuleModel model = new ModuleModel(); JsonResultInfo result = new JsonResultInfo(); this.TryUpdateModel(model); if (this.ModelState.IsValid) { Module module; if (model.ModuleID == 0) module = new Module(); else module = _moduleRepository.FindModule(model.ModuleID); module.AccessLevelID = model.AccessLevelID; module.IsPublish = model.IsPublish; module.ModuleName = model.ModuleName; module.ModuleTypeID = model.ModuleTypeID; module.PositionID = model.PositionID; module.SortOrder = model.SortOrder; module.PublishUp = model.PublishUp; module.PublishDown = model.PublishDown; ModuleType moduleType = _moduleTypeRepository.FindModuleType(module.ModuleTypeID); if (moduleType != null) { string filePath = Path.Combine(Server.MapPath("~/"), "Modules", moduleType.ModuleTypeName, "parameters.xml"); if (System.IO.File.Exists(filePath)) { Parameter p = ParameterHelper.FillParameterValues(System.IO.File.ReadAllText(filePath), collection); MemoryStream stream = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Parameter)); ser.WriteObject(stream, p); stream.Position = 0; StreamReader sr = new StreamReader(stream); module.Parameters = sr.ReadToEnd(); } } result.Errors = _moduleRepository.SaveModule(module); // Save Module Roles if (result.Errors.Any() == false) { _moduleRepository.DeleteModuleRoles(module.ModuleID); if (string.IsNullOrEmpty(collection["RolesIDs"]) == false) { string[] arrRoleIDs = collection["RolesIDs"].Split((",").ToCharArray()); int id = 0; List<ModulesInRoles> moduleRoles = new List<ModulesInRoles>(); foreach (string roleID in arrRoleIDs) { int.TryParse(roleID, out id); moduleRoles.Add(new ModulesInRoles { ModuleID = module.ModuleID, RoleID = id }); } result.Errors = _moduleRepository.SaveModuleRoles(moduleRoles); } } // Save Module Menus if (result.Errors.Any() == false) { _moduleRepository.DeleteModuleMenus(module.ModuleID); if (string.IsNullOrEmpty(collection["MenuIDs"]) == false) { string[] arrMenusIDs = collection["MenuIDs"].Split((",").ToCharArray()); int id = 0; List<ModulesInMenus> moduleMenus = new List<ModulesInMenus>(); foreach (string menuID in arrMenusIDs) { int.TryParse(menuID, out id); moduleMenus.Add(new ModulesInMenus { ModuleID = module.ModuleID, MenuID = id }); } result.Errors = _moduleRepository.SaveModuleMenus(moduleMenus); } } if (result.Errors.Any() == false) { result.ID = module.ModuleID; } } else { result.Errors = ValidationHelper.GetErrorInfo(ModelState); } return Json(result); }
public JsonResult Upload() { JsonResultInfo result = new JsonResultInfo(); List<ErrorInfo> errors = new List<ErrorInfo>(); string uploadpath = Convert.ToString(Request["uploadpath"]); int index; if (string.IsNullOrEmpty(uploadpath) == false) { UploadFileModel model; if (Request.Files != null) { for (index = 0; index < Request.Files.Count; index++) { if (Request.Files[index] != null) { if (string.IsNullOrEmpty(Request.Files[index].FileName) == false) { model = UploadFileHelper.Upload(Request.Files[index], "FileUploadPath", uploadpath, Request.Files[index].FileName); } } } } } else { errors.Add(new ErrorInfo("", "Upload type is required")); } return Json(errors); }