public string GetUploadTypeSelectedText(int UploadTypeId) { UploadsDAL uploads = new UploadsDAL(); var uploadTypes = uploads.GetHRUploadTypes(); return(uploadTypes.Where(u => u.UploadTypeId == UploadTypeId).FirstOrDefault().UploadType); }
public ActionResult LoadRMGUploadDetails(int page, int rows) { UploadsDAL uploads = new UploadsDAL(); try { List <UploadHRDocumentsViewModel> Result = uploads.GetRMGDocumentForDispay(page, rows); if ((Result == null || Result.Count <= 0) && page - 1 > 0) { page = page - 1; Result = uploads.GetHRDocumentForDispay(page, rows); } int totalCount = uploads.GetRMGDocumentForDispayTotalCount(); var totalRecords = totalCount; var totalPages = (int)Math.Ceiling((double)totalRecords / (double)rows); var jsonData = new { total = totalPages, page = page, records = totalRecords, rows = Result }; return(Json(jsonData)); } catch (Exception) { throw; } }
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 Importexcel() { bool uploadStatus = false; string connectionString = ""; if (Request.Files["FileUpload1"].ContentLength > 0) { string extension = System.IO.Path.GetExtension(Request.Files["FileUpload1"].FileName); string uploadsPath = (UploadFileLocation); if (!Directory.Exists(uploadsPath)) { Directory.CreateDirectory(uploadsPath); } string filePath = Path.Combine(uploadsPath, System.IO.Path.GetFileName(Request.Files["FileUpload1"].FileName)); Request.Files["FileUpload1"].SaveAs(filePath); if (extension == ".xls") { connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } else if (extension == ".xlsx") { connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; } OleDbConnection excelConnection = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand("Select [Employee Code],[Reporting Manager Code],[Competency Manager Code],[Confirmation / Exit Process Manager Code],[Business Group],[BusinessGroupID],[Organization Unit],[OrganizationUnitID],[Parent DU],[ParentDUID],[Current DU],[CurrentDUID],[Delivery Team],[DT ID],[Resource Pool Name],[Resource Pool ID],[Skill Name],[Skill ID],[Skill Level],[Proficiency ID],[BusinessGroup],[BusinessGroupID],[Location],[Locationid],[DU],[DUId],[DT],[DTId],[Resourcepoolname],[Resourcepoolid],[Skill],[ToolId],[Description],[ProficiencyId] from [Sheet2$]", excelConnection); //OleDbCommand cmd = new OleDbCommand("Select [Employee Code],[Reporting Manager Code],[Competency Manager Code],[Confirmation / Exit Process Manager Code] from [Sheet2$]", excelConnection); excelConnection.Open(); OleDbDataReader dReader; dReader = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); dt.Load(dReader); ds.Tables.Add(dt); UploadsDAL uploadDAL = new UploadsDAL(); uploadDAL.GetExcelData(ds); uploadStatus = true; excelConnection.Close(); } 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; } }
public List <SelectListItem> GetUploadTypes() { UploadsDAL uploads = new UploadsDAL(); var uploadTypes = uploads.GetHRUploadTypes(); List <SelectListItem> list = new List <SelectListItem>(); foreach (var uploadType in uploadTypes) { list.Add(new SelectListItem { Selected = true, Text = uploadType.UploadType, Value = uploadType.UploadTypeId.ToString() }); } return(list); }
public ActionResult DeleteRMGUploadDetails(int documentId) { UploadsDAL uploads = new UploadsDAL(); HRMSDBEntities dbContext = new HRMSDBEntities(); bool udd = false; try { var parentDoc = dbContext.Tbl_RMG_Documents.Where(x => x.DocumentId == documentId).FirstOrDefault(); var versionDocs = dbContext.Tbl_RMG_DocumentDetail.Where(x => x.DocumentId == documentId).ToList(); string rootFolder = (UploadFileLocationRMG); string subfolderpath = Path.Combine(rootFolder, GetUploadTypeTextFromDocIdRMG(parentDoc.DocumentId)); if (versionDocs != null) { foreach (var d in versionDocs) { string versionDocFilepath = Path.Combine(subfolderpath, d.FileName); if (System.IO.File.Exists(versionDocFilepath)) { System.IO.File.Delete(versionDocFilepath); } } } string Filepath = Path.Combine(subfolderpath, parentDoc.FileName); if (System.IO.File.Exists(Filepath)) { System.IO.File.Delete(Filepath); } udd = uploads.DeleteRMGUploadDetails(documentId); return(Json(udd, JsonRequestBehavior.AllowGet)); } catch (Exception) { udd = false; return(Json(udd, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Action will fire when user clicks on the Filename,to download the file, /// when viewing the history/Details view of files /// </summary> /// <param name="filename"></param> /// <returns></returns> public ActionResult DownloadHRFile(string filename, int uploadTypeId) { HRMSDBEntities dbContext = new HRMSDBEntities(); UploadsDAL RMGupload = new UploadsDAL(); string Loginemployeecode = string.Empty; string[] loginemployeerole = { }; EmployeeDAL empdal = new EmployeeDAL(); int employeeID = empdal.GetEmployeeID(Membership.GetUser().UserName); HRMS_tbl_PM_Employee loginrolescheck = empdal.GetEmployeeDetails(employeeID); Loginemployeecode = loginrolescheck.EmployeeCode; loginemployeerole = Roles.GetRolesForUser(Loginemployeecode); try { if (loginemployeerole.Contains("RMG")) { var documentformchild = (from document in dbContext.Tbl_RMG_Documents join documentDetails in dbContext.Tbl_RMG_DocumentDetail on document.DocumentId equals documentDetails.DocumentId where document.UploadTypeId == uploadTypeId && documentDetails.FileName == filename select documentDetails).FirstOrDefault(); var documentfromparent = (from document in dbContext.Tbl_RMG_Documents where document.UploadTypeId == uploadTypeId && document.FileName == filename select document).FirstOrDefault(); string rootFolder = (UploadFileLocationRMG); string[] FileExtention = filename.Split('.'); string contentType = "application/" + FileExtention[1]; if (documentformchild != null) { string subfolderpath = Path.Combine(rootFolder, GetUploadTypeTextFromDocIdRMG(documentformchild.DocumentId)); string Filepath = Path.Combine(subfolderpath, filename); if (!System.IO.File.Exists(Filepath)) { throw new Exception(); } return(File(Filepath, contentType, filename)); } else { string subfolderpath = Path.Combine(rootFolder, GetUploadTypeTextFromDocIdRMG(documentfromparent.DocumentId)); string Filepath = Path.Combine(subfolderpath, filename); if (!System.IO.File.Exists(Filepath)) { throw new Exception(); } return(File(Filepath, contentType, filename)); } } else { var documentformchild = (from document in dbContext.Tbl_HR_Documents join documentDetails in dbContext.Tbl_HR_DocumentDetail on document.DocumentId equals documentDetails.DocumentId where document.UploadTypeId == uploadTypeId && documentDetails.FileName == filename select documentDetails).FirstOrDefault(); var documentfromparent = (from document in dbContext.Tbl_HR_Documents where document.UploadTypeId == uploadTypeId && document.FileName == filename select document).FirstOrDefault(); string rootFolder = (UploadFileLocation); string[] FileExtention = filename.Split('.'); string contentType = "application/" + FileExtention[1]; if (documentformchild != null) { string subfolderpath = Path.Combine(rootFolder, GetUploadTypeTextFromDocId(documentformchild.DocumentId)); string Filepath = Path.Combine(subfolderpath, filename); if (!System.IO.File.Exists(Filepath)) { throw new Exception(); } return(File(Filepath, contentType, filename)); } else { string subfolderpath = Path.Combine(rootFolder, GetUploadTypeTextFromDocId(documentfromparent.DocumentId)); string Filepath = Path.Combine(subfolderpath, filename); if (!System.IO.File.Exists(Filepath)) { throw new Exception(); } return(File(Filepath, contentType, filename)); } } } catch (Exception) { ConfigurationViewModel model = new ConfigurationViewModel(); model.SearchedUserDetails = new SearchedUserDetails(); string employeeCode = Membership.GetUser().UserName; string[] role = Roles.GetRolesForUser(employeeCode); if (employeeCode != null) { CommonMethodsDAL Commondal = new CommonMethodsDAL(); model.SearchedUserDetails.UserRole = Commondal.GetMaxRoleForUser(role); } return(PartialView("_FileNotFound", model)); } }
/// <summary> /// / /// </summary> /// <param name="documentId"></param> /// <returns></returns> public ActionResult DeleteHRDocsSelected(List <string> filenames) { UploadsDAL uploads = new UploadsDAL(); HRMSDBEntities dbContext = new HRMSDBEntities(); string Loginemployeecode = string.Empty; string[] loginemployeerole = { }; EmployeeDAL empdal = new EmployeeDAL(); int employeeID = empdal.GetEmployeeID(Membership.GetUser().UserName); HRMS_tbl_PM_Employee loginrolescheck = empdal.GetEmployeeDetails(employeeID); Loginemployeecode = loginrolescheck.EmployeeCode; loginemployeerole = Roles.GetRolesForUser(Loginemployeecode); bool result = false; try { if (loginemployeerole.Contains("RMG")) { if (filenames != null) { foreach (string filename in filenames) { var documentformchild = (from document in dbContext.Tbl_RMG_Documents join documentDetails in dbContext.Tbl_RMG_DocumentDetail on document.DocumentId equals documentDetails.DocumentId where documentDetails.FileName == filename select documentDetails).FirstOrDefault(); string rootFolder = (UploadFileLocationRMG); string subfolderpath = Path.Combine(rootFolder, GetUploadTypeTextFromDocIdRMG(documentformchild.DocumentId)); string Filepath = Path.Combine(subfolderpath, filename); if (System.IO.File.Exists(Filepath)) { System.IO.File.Delete(Filepath); } result = uploads.DeleteRMGDocsSelected(filename); } } return(Json(result, JsonRequestBehavior.AllowGet)); } else { if (filenames != null) { foreach (string filename in filenames) { var documentformchild = (from document in dbContext.Tbl_HR_Documents join documentDetails in dbContext.Tbl_HR_DocumentDetail on document.DocumentId equals documentDetails.DocumentId where documentDetails.FileName == filename select documentDetails).FirstOrDefault(); string rootFolder = (UploadFileLocation); string subfolderpath = Path.Combine(rootFolder, GetUploadTypeTextFromDocId(documentformchild.DocumentId)); string Filepath = Path.Combine(subfolderpath, filename); if (System.IO.File.Exists(Filepath)) { System.IO.File.Delete(Filepath); } result = uploads.DeleteHRDocsSelected(filename); } } return(Json(result, JsonRequestBehavior.AllowGet)); } } catch (Exception) { result = false; return(Json(result, JsonRequestBehavior.AllowGet)); } }