public async Task <IActionResult> GetReport() { var type = TempData["type"]; var report = new StiReport(); if (type.Equals("CMR")) { ApplicationConfigurationViewModel appConfig = null; appConfig = await appConfigRepo.GetAppConfigByName("MRXPassword", "Y"); if (appConfig != null && appConfig.AppConfigValue != null) { var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports/EquipmentConditionMonitoring.mrx"); report.LoadEncryptedReport(path, appConfig.AppConfigValue); } else { throw new CustomException("Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template.", "Error", true, "Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template."); } } else if (type.Equals("SR")) { ApplicationConfigurationViewModel appConfig = null; appConfig = await appConfigRepo.GetAppConfigByName("MRXPassword", "Y"); if (appConfig != null && appConfig.AppConfigValue != null) { var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports/SummaryReport.mrx"); report.LoadEncryptedReport(path, appConfig.AppConfigValue); } else { throw new CustomException("Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template.", "Error", true, "Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template."); } } string newConnectionString = Configuration.GetConnectionString("SKF.Master"); report.Dictionary.Databases.Clear(); report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("C2Maintenance", newConnectionString)); if (type.Equals("CMR")) { report.Dictionary.Variables["@JobEquipmentId"].ValueObject = TempData["jeId"]; } else if (type.Equals("SR")) { report.Dictionary.Variables["@JobId"].ValueObject = TempData["jId"]; report.Dictionary.Variables["@ClientSiteId"].ValueObject = TempData["cId"]; } report.Dictionary.Variables["@LanguageId"].ValueObject = TempData["lId"]; return(StiNetCoreViewer.GetReportResult(this, report)); }
public async Task <ApplicationConfigurationViewModel> GetAppConfig(string AppConfigName, string Status) { appConfig = await appConfigRepo.GetAppConfigByName(AppConfigName, Status); if (appConfig != null) { return(appConfig); } else { throw new CustomException("Application Config is missing, Please Contact Support !!!", "Error", true, "Application Configuration is missing for name (" + AppConfigName + ")"); } }
public async Task <IActionResult> ExportLeverage([FromBody] LeverageExportViewModel lvm) { try { CurrentUser cUser = new CurrentUser(HttpContext, _configuration); lvm.UserId = cUser.UserId; var appConfig = await appConfigRepo.GetAppConfigByName("LeverageFilePath", "Y"); lvm.FilePath = appConfig.AppConfigValue; return(Ok(await leverageExportRepo.SaveExportLeverageFiles(lvm))); } catch (CustomException cex) { var responseObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, responseObj)); } catch (Exception ex) { return(Ok(new EmaintenanceMessage(ex.Message))); } }
public async Task <IActionResult> GetAppConfigByName(string name) { return(Ok(await applicationConfigurationRepo.GetAppConfigByName(name, "Y"))); }
public async Task <List <FileUploadViewModel> > UploadFiles(HttpRequest Request, HttpContext HttpContext) { try { var files = Request.Form.Files; var customHeaders = Request.Headers; StringValues aId = ""; StringValues Type = ""; StringValues PlotType = ""; // Local variable to handle. string FilePath = ""; string ImageUrl = ""; Boolean isExternalPath = true; string SubPath = ""; string TypeFormat = ""; string Delimiter = ""; var dir = ""; List <FileUploadViewModel> fuvms = new List <FileUploadViewModel>(); ApplicationConfigurationViewModel appConfig = null; if (customHeaders.ContainsKey("aId") && customHeaders.ContainsKey("Type")) { customHeaders.TryGetValue("aId", out aId); customHeaders.TryGetValue("Type", out Type); appConfig = await appConfigRepo.GetAppConfigByName("BaseFilePath", "Y"); FilePath = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("ImageUrl", "Y"); ImageUrl = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("IsExternalPath", "Y"); if (appConfig.AppConfigValue != null) { isExternalPath = bool.Parse(appConfig.AppConfigValue); // This will used to store the files inside the application. if (!isExternalPath) { dir = Directory.GetCurrentDirectory() + $@"\wwwroot\" + FilePath; //FilePath = _dir + FilePath; } else { dir = FilePath; } } if (Type == "Equipment") { appConfig = await appConfigRepo.GetAppConfigByName("EquipmentPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("EquipmentSubPath", "Y"); SubPath = appConfig.AppConfigValue; } if (Type == "Drive") { appConfig = await appConfigRepo.GetAppConfigByName("DrivePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; //TypeFormat = "DR"; appConfig = await appConfigRepo.GetAppConfigByName("DriveSubPath", "Y"); SubPath = appConfig.AppConfigValue; //SubPath = "Attachments//Equipment//"; } if (Type == "Intermediate") { appConfig = await appConfigRepo.GetAppConfigByName("IntermediatePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("IntermediateSubPath", "Y"); SubPath = appConfig.AppConfigValue; } if (Type == "Driven") { appConfig = await appConfigRepo.GetAppConfigByName("DrivenPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("DrivenSubPath", "Y"); SubPath = appConfig.AppConfigValue; } if (Type == "UnitAnalysis") { appConfig = await appConfigRepo.GetAppConfigByName("UnitAnalysisPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("UnitAnalysisSubPath", "Y"); SubPath = appConfig.AppConfigValue; } if (Type == "ClientDoc") { appConfig = await appConfigRepo.GetAppConfigByName("ClientDocPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("ClientDocSubPath", "Y"); SubPath = appConfig.AppConfigValue; SubPath = SubPath + aId + "\\"; } if (Type == "OtherReports") { appConfig = await appConfigRepo.GetAppConfigByName("OtherReportsPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("OtherReportsSubPath", "Y"); SubPath = appConfig.AppConfigValue; SubPath = SubPath + aId + "\\"; } if (Type == "TechUpgrade") { appConfig = await appConfigRepo.GetAppConfigByName("TechUpgradePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("TechUpgradeSubPath", "Y"); SubPath = appConfig.AppConfigValue; SubPath = SubPath + aId + "\\"; } if (Type == "FailureReport") { appConfig = await appConfigRepo.GetAppConfigByName("FailureReportPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("FailureReportSubPath", "Y"); SubPath = appConfig.AppConfigValue; } if (Type == "AvoidedPlannedMaintenence") { appConfig = await appConfigRepo.GetAppConfigByName("AvoidedPlannedMaintenancePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("AvoidedPlannedMaintenenceSubPath", "Y"); SubPath = appConfig.AppConfigValue; } if (Type == "ClientSite") { appConfig = await appConfigRepo.GetAppConfigByName("ClientSitePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("ClientSiteSubPath", "Y"); SubPath = appConfig.AppConfigValue; SubPath = SubPath + aId + "\\"; } if (Type == "Leverage") { appConfig = await appConfigRepo.GetAppConfigByName("LeveragePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("LeverageSubPath", "Y"); SubPath = appConfig.AppConfigValue; SubPath = SubPath + aId + "\\"; } if (Type == "ImagePlot") { if (customHeaders.ContainsKey("plotType")) { customHeaders.TryGetValue("plotType", out PlotType); appConfig = PlotType == "PL" ? await appConfigRepo.GetAppConfigByName("PlantImagePlotFormat", "Y") : PlotType == "EQ" ? await appConfigRepo.GetAppConfigByName("EquipmentImagePlotFormat", "Y") : PlotType == "AS" ? await appConfigRepo.GetAppConfigByName("AssetImagePlotFormat", "Y") : await appConfigRepo.GetAppConfigByName("ImagePlotFormat", "Y"); } TypeFormat = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("ImagePlotSubPath", "Y"); SubPath = appConfig.AppConfigValue; } } var dateFormat = "yyyyMMddHHmmssFFF"; // Returns 20190118183526247 appConfig = await appConfigRepo.GetAppConfigByName("FileNameDateFormat", "Y"); if (appConfig.AppConfigValue != null) { dateFormat = appConfig.AppConfigValue; } string LogicalFilePattern = TypeFormat + Delimiter + aId + Delimiter; CurrentUser cUser = new CurrentUser(HttpContext, _configuration); foreach (IFormFile file in files) { string _LogicalFilePattern = null; _LogicalFilePattern = LogicalFilePattern + DateTime.Now.ToString(dateFormat); // The below method call is used to write the Files in a specified Location and return the Save Parameters. fuvms.Add(CopyFilesToLocation(file, _LogicalFilePattern, dir + SubPath, ImageUrl + SubPath)); // The below code will save the return parameters in DataBase based on Type (Equipment | Drive | Intermediate | Driven). //await equipmentRepo.SaveOrUpdateAttachments(Type, Int32.Parse(aId), 0, fuvm.OriginalFileName, fuvm.LogicalFileName, fuvm.PhysicalFilePath, "Y", cUser.UserId); } return(fuvms); } catch (Exception ex) { throw new CustomException(ex.Message, "Error", true, ex?.ToString()); } }
public async Task <IActionResult> GetReport() { CurrentUser cUser = new CurrentUser(HttpContext, _configuration); var report = new StiReport(); ApplicationConfigurationViewModel appConfig = null; appConfig = await appConfigRepo.GetAppConfigByName("MRXPassword", "Y"); // This is to load Admin Dashboard if (customAuthService.CheckPermission(cUser.UserId, "PRG53", "P1")) { if (appConfig != null && appConfig.AppConfigValue != null) { var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports/EmaintAnalystDashboard.mrx"); report.LoadEncryptedReport(path, appConfig.AppConfigValue); } else { throw new CustomException("Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template.", "Error", true, "Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template."); } } // This is to load Client Dashboard else if (customAuthService.CheckPermission(cUser.UserId, "PRG54", "P1")) { if (appConfig != null && appConfig.AppConfigValue != null) { var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports/EmaintClientDashboard.mrx"); report.LoadEncryptedReport(path, appConfig.AppConfigValue); } else { throw new CustomException("Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template.", "Error", true, "Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template."); } } // This is to load Warning MRX states, "Insufficient Privilege Please contact your Administrator" else { if (appConfig != null && appConfig.AppConfigValue != null) { var path = Path.Combine(_hostingEnvironment.WebRootPath, "reports/UnauthorizedDashboard.mrt"); report.Load(path); return(StiNetCoreViewer.GetReportResult(this, report)); } else { throw new CustomException("Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template.", "Error", true, "Unable to Load Data, Please Contact Support!!!, Please provide a valid password to read the Report Template."); } } string newConnectionString = _configuration.GetConnectionString("SKF.Master"); report.Dictionary.Databases.Clear(); report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("C2Maintenance", newConnectionString)); Stimulsoft.Report.Dashboard.StiCacheCleaner.Clean(report.Key); report.Key = StiKeyHelper.GenerateKey(); //report.Dictionary.Variables["@ClientSiteId"].ValueObject = TempData["csId"]; report.Dictionary.Variables["@UserId"].ValueObject = cUser.UserId; report.Dictionary.Variables["@LanguageId"].ValueObject = TempData["lId"]; return(StiNetCoreViewer.GetReportResult(this, report)); }
public async Task <IActionResult> UploadFilesAjax() { try { var files = Request.Form.Files; var customHeaders = Request.Headers; StringValues aId = ""; StringValues Type = ""; string FilePath = ""; Boolean isExternalPath = true; string SubPath = ""; string TypeFormat = ""; string Delimiter = ""; var dir = ""; ApplicationConfigurationViewModel appConfig = null; if (customHeaders.ContainsKey("aId") && customHeaders.ContainsKey("Type")) { customHeaders.TryGetValue("aId", out aId); customHeaders.TryGetValue("Type", out Type); appConfig = await appConfigRepo.GetAppConfigByName("BaseFilePath", "Y"); FilePath = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("IsExternalPath", "Y"); if (appConfig.AppConfigValue != null) { isExternalPath = bool.Parse(appConfig.AppConfigValue); // This will used to store the files inside the application. if (isExternalPath) { dir = Directory.GetCurrentDirectory() + $@"\wwwroot\" + FilePath; //FilePath = _dir + FilePath; } } if (Type == "Equipment") { appConfig = await appConfigRepo.GetAppConfigByName("EquipmentPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; //TypeFormat = "EQ"; appConfig = await appConfigRepo.GetAppConfigByName("EquipmentSubPath", "Y"); SubPath = appConfig.AppConfigValue; //SubPath = "Attachments//Equipment//"; } if (Type == "Drive") { appConfig = await appConfigRepo.GetAppConfigByName("DrivePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; //TypeFormat = "DR"; appConfig = await appConfigRepo.GetAppConfigByName("DriveSubPath", "Y"); SubPath = appConfig.AppConfigValue; //SubPath = "Attachments//Equipment//"; } if (Type == "Intermediate") { appConfig = await appConfigRepo.GetAppConfigByName("IntermediatePrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; //TypeFormat = "IN"; appConfig = await appConfigRepo.GetAppConfigByName("IntermediateSubPath", "Y"); SubPath = appConfig.AppConfigValue; //SubPath = "Attachments//Equipment//"; } if (Type == "Driven") { appConfig = await appConfigRepo.GetAppConfigByName("DrivenPrefixFormat", "Y"); TypeFormat = appConfig.AppConfigValue; //TypeFormat = "DN"; appConfig = await appConfigRepo.GetAppConfigByName("DrivenSubPath", "Y"); SubPath = appConfig.AppConfigValue; //SubPath = "Attachments//Equipment//"; } } var dateFormat = "yyyyMMddHHmmssFFF"; // Returns 20190118183526247 appConfig = await appConfigRepo.GetAppConfigByName("FileNameDateFormat", "Y"); if (appConfig.AppConfigValue != null) { dateFormat = appConfig.AppConfigValue; } string LogicalFilePattern = TypeFormat + Delimiter + aId + Delimiter; CurrentUser cUser = new CurrentUser(HttpContext, _configuration); foreach (IFormFile file in files) { LogicalFilePattern = LogicalFilePattern + DateTime.Now.ToString(dateFormat); // The below method call is used to write the Files in a specified Location and return the Save Parameters. FileUploadViewModel fuvm = fileUploadService.CopyFilesToLocation(file, LogicalFilePattern, dir + SubPath, FilePath + SubPath); // The below code will save the return parameters in DataBase based on Type (Equipment | Drive | Intermediate | Driven). //await equipmentRepo.SaveOrUpdateAttachments(Type, Int32.Parse(aId), 0, fuvm.OriginalFileName, fuvm.LogicalFileName, fuvm.PhysicalFilePath, "Y", cUser.UserId); } return(Json("Success")); } catch (CustomException cex) { var responseObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, responseObj)); } catch (Exception ex) { return(Ok(new EmaintenanceMessage(ex.Message))); } }
public async Task <dynamic> SendInvite(EmailViewModel emailViewModel) { ApplicationConfigurationViewModel appConfig = null; string SmtpUrl = null; string SmtpUN = null; string SmtpPwd = null; string SenderEmailId = null; int Port = 0; bool EnableSsl = false; try { appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_URL", "Y"); SmtpUrl = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_UN", "Y"); SmtpUN = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_PWD", "Y"); SmtpPwd = CustomUtils.DecodeFromBase64(appConfig.AppConfigValue); appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_PORT", "Y"); Port = Int32.Parse(appConfig.AppConfigValue); appConfig = await appConfigRepo.GetAppConfigByName("O_SENDER_EMAIL", "Y"); SenderEmailId = appConfig.AppConfigValue; appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_ENABLE_SSL", "Y"); EnableSsl = bool.Parse(appConfig.AppConfigValue); // Create SMTP Client. SmtpClient sc = new SmtpClient(SmtpUrl); NetworkCredential nc = new NetworkCredential(SmtpUN, SmtpPwd); sc.Port = Port; sc.EnableSsl = EnableSsl; sc.Credentials = nc; // Setup e-mail message System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); if (emailViewModel.FromEmail != null && emailViewModel.FromEmail.EmailId != null) { msg.From = new MailAddress(emailViewModel.FromEmail.EmailId); } else { EmailAttributesViewModel emailAttr = new EmailAttributesViewModel(); emailAttr.EmailId = SenderEmailId; emailAttr.Name = SenderEmailId; emailViewModel.FromEmail = emailAttr; msg.From = new MailAddress(SenderEmailId); } AddToEmails(msg, emailViewModel.ToEmailList); ApplicationConfigurationViewModel sub = await appConfigRepo.GetAppConfigByName("O_APP_ENV", "Y"); if (sub != null && sub.AppConfigValue != null && sub.AppConfigValue != "") { emailViewModel.Subject = sub.AppConfigValue + " " + emailViewModel.Subject; msg.Subject = emailViewModel.Subject; } else { msg.Subject = emailViewModel.Subject; } msg.Body = emailViewModel.Body; msg.IsBodyHtml = true; if (emailViewModel.Attachments != null && emailViewModel.Attachments.Count > 0) { // Need to write code for Attachments. } // The below method is used to send an Calendar Invite. if (emailViewModel.IsCalendarInvite) { StringBuilder str = new StringBuilder(); str.AppendLine("BEGIN:VCALENDAR"); str.AppendLine("PRODID:-//" + emailViewModel.FromEmail.EmailId); str.AppendLine("VERSION:2.0"); str.AppendLine("X-WR-TIMEZONE:Asia/Kolkata"); str.AppendLine("CALSCALE:GREGORIAN"); str.AppendLine("METHOD:REQUEST"); str.AppendLine("BEGIN:VEVENT"); str.AppendLine(string.Format("SUMMARY:{0}", emailViewModel.Subject)); str.AppendLine(string.Format("DESCRIPTION:{0}", emailViewModel.Body)); //str.AppendLine("BEGIN:VTIMEZONE"); str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", emailViewModel.StartDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"))); str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", new DateTime().ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"))); str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", emailViewModel.EndDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"))); str.AppendLine("LOCATION:" + emailViewModel.Location); //str.AppendLine("END:VTIMEZONE"); str.AppendLine("CLASS:PUBLIC"); str.AppendLine("IMPORTANT:0"); str.AppendLine("STATUS: CONFIRMED"); str.AppendLine("COMMENT:"); str.AppendLine(string.Format("UID:{0}", Guid.NewGuid())); str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", emailViewModel.Body)); str.AppendLine(string.Format("ORGANIZER;CN=\"{0}\":MAILTO:{0}", emailViewModel.FromEmail.EmailId)); foreach (MailAddress emto in msg.To) { str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;RSVP=TRUE;PARTSTAT=NEEDS-ACTION:mailto:{1}", emto.DisplayName, emto.Address)); } //str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", emto.DisplayName, emto.Address)); //str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, msg.To[0].Address)); str.AppendLine("BEGIN:VALARM"); str.AppendLine("TRIGGER:-PT15M"); //str.AppendLine("ACTION:DISPLAY"); str.AppendLine("ACTION:EMAIL"); str.AppendLine("DESCRIPTION:Reminder"); str.AppendLine("END:VALARM"); str.AppendLine("END:VEVENT"); str.AppendLine("END:VCALENDAR"); System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar"); ct.Parameters.Add("method", "REQUEST"); AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct); msg.AlternateViews.Add(avCal); } try { sc.Send(msg); return("Success"); } catch (Exception ex) { return("Fail Reason +++++++++ " + ex); } } catch (Exception e) { return("" + e); } return(string.Empty); }