public ActionResult UploadRMGDocument(HttpPostedFileBase doc, UploadHRDocumentsViewModel model) { UploadsDAL uploads = new UploadsDAL(); bool uploadStatus = false; if (doc.ContentLength > 0) { string uploadsPath = (UploadFileLocationRMG); uploadsPath = Path.Combine(uploadsPath, GetUploadTypeSelectedText(1)); string fileName = Path.GetFileName(doc.FileName); try { IDocuments document = null; if (!uploads.IsRMGDocumentExists(Path.GetFileName(doc.FileName), model.UploadTypeId)) { // Insert new record to parent document = new Tbl_RMG_Documents(); document.FileName = Path.GetFileName(doc.FileName); ((Tbl_RMG_Documents)document).FileDescription = model.FileDescription; ((Tbl_RMG_Documents)document).UploadTypeId = 1; } else { // Insert new record to child document = new Tbl_RMG_DocumentDetail(); int documentID = 0; string newNameForDocument = uploads.GetNewNameForRMGDocument(Path.GetFileName(doc.FileName), 1, out documentID); fileName = newNameForDocument; document.DocumentId = documentID; document.FileName = newNameForDocument; } document.FilePath = uploadsPath; document.Comments = model.Comments; document.FileDescription = model.FileDescription; document.UploadedBy = int.Parse(HttpContext.User.Identity.Name); document.UploadedDate = DateTime.Now; uploads.UploadRMGDocument(document); string filePath = Path.Combine(uploadsPath, fileName); if (!Directory.Exists(uploadsPath)) { Directory.CreateDirectory(uploadsPath); } doc.SaveAs(filePath); uploadStatus = true; } catch (Exception) { //throw; } } return(Json(new { status = uploadStatus }, "text/html", JsonRequestBehavior.AllowGet)); }
public ActionResult ShowHistoryRMGDocUploads(int documentId, string uploadType) { HRMSDBEntities dbContext = new HRMSDBEntities(); UploadsDAL uploads = new UploadsDAL(); List <Tbl_RMG_DocumentDetail> objHRDocDetails = new List <Tbl_RMG_DocumentDetail>(); Tbl_RMG_Documents objhRDoc = new Tbl_RMG_Documents(); List <UploadHRDocumentsViewModel> objDocList = new List <UploadHRDocumentsViewModel>(); int uploadTypeId = dbContext.Tbl_HR_UploadType.Where(x => x.UploadType == uploadType).FirstOrDefault().UploadTypeId; try { objhRDoc = uploads.GetRMGDocument(documentId); objHRDocDetails = uploads.GetRMGDocumentHistoryForDisplay(documentId); foreach (Tbl_RMG_DocumentDetail eachDocDetail in objHRDocDetails) { UploadHRDocumentsViewModel dd = new UploadHRDocumentsViewModel() { DocumentID = eachDocDetail.DocumentId, Comments = eachDocDetail.Comments, FileDescription = eachDocDetail.FileDescription, FileName = eachDocDetail.FileName, UploadedBy = uploads.GetUploadNameFromUploadById(HttpContext.User.Identity.Name), UploadedDate = (eachDocDetail.UploadedDate).Value, FilePath = eachDocDetail.FilePath, UploadTypeId = uploadTypeId }; objDocList.Add(dd); } UploadHRDocumentsViewModel dd1 = new UploadHRDocumentsViewModel() { DocumentID = objhRDoc.DocumentId, Comments = objhRDoc.Comments, FileDescription = objhRDoc.FileDescription, FileName = objhRDoc.FileName, UploadedBy = uploads.GetUploadNameFromUploadById(HttpContext.User.Identity.Name), UploadedDate = (objhRDoc.UploadedDate).Value, FilePath = objhRDoc.FilePath, UploadTypeId = uploadTypeId }; objDocList.Add(dd1); return(PartialView("_ShowHRDocHistory", objDocList)); } catch (Exception Ex) { throw Ex; } }