public ActionResult UploadInfoFile(string infoTypeCode) { IdxInfoUploadModels model = new IdxInfoUploadModels(); model.infoTypeCode = infoTypeCode; model.infoTypeList = this.initTypeList(); model.postedDate = DateTime.Now.ToString(Constants.DateTimeFormat); return View(model); }
public bool uploadIdxInfoFile(IdxInfoUploadModels model, string userCode, string uploadFolder) { string fileUrl = string.Empty; string fileName = string.Empty; IdxInfoModels data = new IdxInfoModels(); if (model.infoFile != null) { fileName = DateTime.Now.ToString("yyMMddHHmmssfff") + model.infoFile.FileName; //string fileName = "~/Content/UploadFiles/Index/" + DateTime.Now.ToString("yyMMddHHmmssfff") + indexFileUpload.indexFile.FileName; //string filePath = Path.Combine(uploadFolder, fileName); //model.infoFile.SaveAs(filePath); data.fileContent = new byte[model.infoFile.InputStream.Length]; long bytesRead = model.infoFile.InputStream.Read(data.fileContent, 0, (int)model.infoFile.InputStream.Length); model.infoFile.InputStream.Close(); } else { model.errorMessage = String.Format(PsMModel.Resource.MsgRequired, PsMModel.Resource.InfoFile); return false; } fileUrl = Path.Combine(Constants.File.UploadInfoFolder, fileName); data.infoCode = Utils.UtilsDAO.GenerateCode(Constants.CodePrefix.IdxInfo); data.infoTypeCode = model.infoTypeCode; data.fileUrl = fileUrl; data.fileName = model.infoFile.FileName; data.infoStatus = Constants.Status.Active; data.postedDate = DateTime.ParseExact(model.postedDate, Constants.DateTimeFormat, null); data.createdDate = DateTime.Now; data.createdBy = userCode; data.updatedDate = DateTime.Now; data.updatedBy = userCode; mapper.Insert("Idx.insertIdxInfo", data); model.infoMessage = PsMModel.Resource.MsgSuccess; return true; }
public ActionResult UploadInfoFile(IdxInfoUploadModels model) { if (ModelState.IsValid) { SysUserModels userSession = (SysUserModels)Session["UserSession"]; IdxInfoDAO idxDAO = new IdxInfoDAO(this.mapper); model.infoFile = Request.Files["infoFile"]; string uploadFolder = Server.MapPath(Constants.File.UploadInfoFolder); idxDAO.uploadIdxInfoFile(model, userSession.userCode, uploadFolder); } model.infoTypeList = this.initTypeList(); return View(model); }