public async Task SendMail() { if (!await new NotificationDAO().IsSend()) { #region *) Field var userprofile = Session["UserProfile"] as UserProfileVM; var auditUploadModel = new ActionPlanDAO().CheckLateOnUpdateData(userprofile.User.ID); var model = new ActionPlanDAO().CheckDeadline(); #endregion #region 1) Late On Update Thread lateOnTask = new Thread(async() => await CheckLateOnUpdate(auditUploadModel)); lateOnTask.Start(); #endregion #region 2) Check Late On Task Thread lateOnUpload = new Thread(async() => await CheckLateOnTask(model)); lateOnUpload.Start(); #endregion #region *) Thông báo để biết gửi mail hay chưa var itemSendMail = new StateSendMail(); await new NotificationDAO().AddSendMail(itemSendMail); new ErrorMessageDAO().Add(new ErrorMessage { Function = "Send Mail", Name = "[KPI System] Late on task, [KPI System] Late on upload data" }); #endregion } }
/// <summary> /// Update an action plan /// </summary> /// <param name="actionPlanObj">ActionPlanUpdateModel</param> /// <returns>ActionPlanModel</returns> public async Task <ActionPlanModel> UpdateActionPlan(ActionPlanUpdateModel actionPlanObj) { ActionPlanDAO plan = await _repoActionPlans.GetItemAsync(actionPlanObj.ActionPlanId); if (plan == null) { throw new Exception($"No action plan found that matches responseid: {actionPlanObj.ActionPlanId}"); } string etag = plan.ETag; DateTime creationDate = plan.CreationDate; plan = _mapper.Map <ActionPlanDAO>(actionPlanObj); plan.ETag = etag; plan.CreationDate = creationDate; try { await _repoActionPlans.UpdateItemAsync(plan); } catch (DocumentClientException e) { //Update concurrency issue, retrying if (e.StatusCode == HttpStatusCode.PreconditionFailed) { return(await UpdateActionPlan(actionPlanObj)); } throw e; } var output = _mapper.Map <ActionPlanModel>(plan); return(output); }
public ActionResult Index() { BreadCrumb.Add("/", "Home"); BreadCrumb.SetLabel("Dashboard"); ViewBag.TotalUser = new UserAdminDAO().Total().ToInt(); ViewBag.TotalKPI = new KPIAdminDAO().Total().ToInt(); ViewBag.TotalLevel = new LevelDAO().Total().ToInt(); ViewBag.TotalKPILevel = new KPILevelDAO().Total().ToInt(); ViewBag.TotalCategory = new AdminCategoryDAO().Total().ToInt(); var model = new ActionPlanDAO().CheckDeadline(); var userprofile = Session["UserProfile"] as UserProfileVM; foreach (var item in model) { if (!new ActionPlanDAO().IsSentMailActionPlan(userprofile.User.ID, item.ActionplanID)) { string content = "Please note that the action plan we going to deadline on " + item.Deadline; var html = string.Empty; string from = ConfigurationManager.AppSettings["FromEmailAddress"].ToSafetyString(); string password = ConfigurationManager.AppSettings["FromEmailPassword"].ToSafetyString(); string to = item.Email.ToSafetyString(); string clientHost = ConfigurationManager.AppSettings["ClientHost"].ToSafetyString(); string subject = ConfigurationManager.AppSettings["FromEmailDisplayName"].ToSafetyString(); MailMessage mail = new MailMessage(); mail.To.Add(to.ToString()); mail.From = new MailAddress(from, "KPI.App"); mail.Subject = subject; mail.Body = content; mail.IsBodyHtml = false; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.Priority = MailPriority.High; try { using (var smtp = new SmtpClient()) { smtp.UseDefaultCredentials = true; smtp.Host = clientHost; smtp.Send(mail); } var itemND = new ActionPlanDetail(); itemND.ActionPlanID = item.ActionplanID; itemND.UserID = userprofile.User.ID; itemND.Sent = true; new ActionPlanDAO().AddActionDetail(itemND); return(Json(new { status = true, isSendmail = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var a = new ErrorMessage(); a.Name = ex.Message; new ErrorMessageDAO().Add(a); return(Json(new { status = true, isSendmail = false }, JsonRequestBehavior.AllowGet)); } } } return(View()); }
/// <summary> /// Create an action plan /// </summary> /// <param name="actionPlanObj">ActionPlanCreationModel</param> /// <returns>ActionPlanModel</returns> public async Task <ActionPlanModel> CreationActionPlan(ActionPlanCreationModel actionPlanObj) { ActionPlanDAO plan = _mapper.Map <ActionPlanDAO>(actionPlanObj); plan.Id = await _repoActionPlans.CreateItemAsync(plan); if (_repoActionPlans.IsDocumentKeyNull(plan)) { throw new Exception($"An error occured when creating a new action plan"); } return(_mapper.Map <ActionPlanModel>(plan)); }
public async Task SendMail() { if (!await new NotificationDAO().IsSend()) { #region *) Field var userprofile = Session["UserProfile"] as UserProfileVM; string host = ConfigurationManager.AppSettings["Http"].ToSafetyString(); string contentForAuditUpload = System.IO.File.ReadAllText(Server.MapPath("~/Templates/LateOnUpDateData.html")); contentForAuditUpload = contentForAuditUpload.Replace("{{{content}}}", @"<b style='color:red'>Late On Update Data</b><br/>Your KPIs have expired as below list: "); string contentForDeadline = System.IO.File.ReadAllText(Server.MapPath("~/Templates/LateOnTask.html")); contentForDeadline = contentForDeadline.Replace("{{{content}}}", @"<b style='color:red'>Late On Task</b><br/>Your task have expired as below list: "); var htmlForUpload = string.Empty; var htmlForDeadLine = string.Empty; var count = 0; var auditUploadModel = new ActionPlanDAO().CheckLateOnUpdateData(userprofile.User.ID); var model = new ActionPlanDAO().CheckDeadline(); #endregion #region 1) Late On Update if (await new SettingDAO().IsSendMail("CHECKLATEONUPDATEDATA")) { foreach (var item2 in auditUploadModel.Item1) { count++; htmlForUpload += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{area}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{ockpicode}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{year}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToSafetyString()) .Replace("{{area}}", item2[3].ToSafetyString()) .Replace("{{kpiname}}", item2[0].ToSafetyString()) .Replace("{{ockpicode}}", item2[2].ToSafetyString()) .Replace("{{year}}", item2[4].ToSafetyString()) .Replace("{{deadline}}", item2[1].ToSafetyString()); } contentForAuditUpload = contentForAuditUpload.Replace("{{{html-template}}}", htmlForUpload); if (auditUploadModel.Item1.Count > 0) { Commons.SendMail(auditUploadModel.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on upload data", contentForAuditUpload, "Late on upload data"); } } #endregion #region 2) Check Dead Line if (await new SettingDAO().IsSendMail("CHECKDEADLINE")) { foreach (var item in model.Item1) { //string content = "Please note that the action plan we are overdue on " + item.Deadline; count++; htmlForDeadLine += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToString()) .Replace("{{kpiname}}", item[0].ToSafetyString()) .Replace("{{deadline}}", item[1].ToSafetyString("MM/dd/yyyy")); } contentForDeadline = contentForDeadline.Replace("{{{html-template}}}", htmlForDeadLine); if (model.Item1.Count > 0) { Commons.SendMail(model.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on task", contentForDeadline, "Late on task "); } } #endregion #region *) Thông báo để biết gửi mail hay chưa var itemSendMail = new StateSendMail(); await new NotificationDAO().AddSendMail(itemSendMail); new ErrorMessageDAO().Add(new ErrorMessage { Function = "Send Mail", Name = "[KPI System] Late on task, [KPI System] Late on upload data" }); #endregion } }
/// <summary> /// Get action plan from an action plan Id /// </summary> /// <param name="actionPlanId">Action Plan Id</param> /// <returns>ActionPlanModel</returns> public async Task <ActionPlanModel> GetActionPlan(Guid actionPlanId) { ActionPlanDAO plan = await _repoActionPlans.GetItemAsync(actionPlanId); return(_mapper.Map <ActionPlanModel>(plan)); }
public WorkplaceController() { _dao = new UploadDAO(); _daoActionPlan = new ActionPlanDAO(); }
public async Task Execute(IJobExecutionContext context) { //throw new NotImplementedException(); string from = ConfigurationManager.AppSettings["FromEmailAddress"].ToSafetyString(); string host = ConfigurationManager.AppSettings["Http"].ToSafetyString(); string content2 = System.IO.File.ReadAllText(host + "/Templates/LateOnUpDateData.html"); content2 = content2.Replace("{{{content}}}", "Your below KPIs have expired: "); string content = System.IO.File.ReadAllText(host + "/Templates/LateOnTask.html"); content = content.Replace("{{{content}}}", "Your below KPIs have expired: "); var html = string.Empty; var count = 0; var model2 = new ActionPlanDAO().CheckLateOnUpdateData(1); var model = new ActionPlanDAO().CheckDeadline(); if (await new SettingDAO().IsSendMail("CHECKLATEONUPDATEDATA")) { foreach (var item2 in model2.Item1) { count++; html += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{year}}</td> </tr>" .Replace("{{no}}", count.ToSafetyString()) .Replace("{{kpiname}}", item2[0].ToSafetyString()) .Replace("{{year}}", item2[1].ToSafetyString()); content2 = content2.Replace("{{{html-template}}}", html); } Commons.SendMail(model2.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on upload data", content2, "Late on upload data"); } if (await new SettingDAO().IsSendMail("CHECKDEADLINE")) { foreach (var item in model.Item1) { //string content = "Please note that the action plan we are overdue on " + item.Deadline; count++; html += @"<tr> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{no}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{kpiname}}</td> <td valign='top' style='padding:5px; font-family: Arial,sans-serif; font-size: 16px; line-height:20px;'>{{deadline}}</td> </tr>" .Replace("{{no}}", count.ToString()) .Replace("{{kpiname}}", item[0].ToSafetyString()) .Replace("{{deadline}}", item[1].ToSafetyString("MM/dd/yyyy")); content = content.Replace("{{{html-template}}}", html); } Commons.SendMail(model.Item2.Select(x => x.Email).ToList(), "[KPI System] Late on task", content, "Late on task "); } var itemSendMail = new StateSendMail(); await new NotificationDAO().AddSendMail(itemSendMail); var hh = ConfigurationManager.AppSettings["hh"].ToInt(); var mm = ConfigurationManager.AppSettings["mm"].ToInt(); var db = new KPIDbContext(); var items = new ErrorMessage() { Function = "Test window service " + hh + ":" + mm, Name = "EmailJob" }; db.ErrorMessages.Add(items); await db.SaveChangesAsync(); db.Dispose(); }
public JsonResult Add(ActionPlanViewModel2 obj) { var item = new ActionPlan(); item.Title = obj.Title; item.Description = obj.Description; item.KPILevelCodeAndPeriod = obj.KPILevelCodeAndPeriod; item.Tag = obj.Tag; item.UserID = obj.UserID; item.DataID = obj.DataID; item.CommentID = obj.CommentID; item.Link = obj.Link; item.SubmitDate = obj.SubmitDate.ToDateTime(); item.Deadline = obj.Deadline.ToDateTime(); var data = new ActionPlanDAO().Add(item, obj.Subject); if (data.Status) { if (data.ListEmails.Count > 0) { foreach (var item2 in data.ListEmails) { string content = item2[0] + "mentioned you in KPI System Apps. Content: " + item2[4] + ". " + item2[3] + " Link: " + item2[2]; var html = string.Empty; var sessionUser = Session["UserProfile"] as UserProfileVM; string from = ConfigurationManager.AppSettings["FromEmailAddress"].ToSafetyString(); string password = ConfigurationManager.AppSettings["FromEmailPassword"].ToSafetyString(); string to = item2[1].ToSafetyString(); string clientHost = ConfigurationManager.AppSettings["ClientHost"].ToSafetyString(); string subject = ConfigurationManager.AppSettings["FromEmailDisplayName"].ToSafetyString(); MailMessage mail = new MailMessage(); mail.To.Add(to.ToString()); mail.From = new MailAddress(from, "KPI.App"); mail.Subject = subject; mail.Body = content; mail.IsBodyHtml = false; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.Priority = MailPriority.High; try { using (var smtp = new SmtpClient()) { smtp.UseDefaultCredentials = true; smtp.Host = clientHost; smtp.Send(mail); } return(Json(new { status = true, isSendmail = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var a = new ErrorMessage(); a.Name = ex.Message; new ErrorMessageDAO().Add(a); return(Json(new { status = true, isSendmail = false }, JsonRequestBehavior.AllowGet)); } } } } return(Json(new { status = false, isSendmail = false }, JsonRequestBehavior.AllowGet)); }
public static List <ActionPlanDAO> GetActionPlans() { List <ActionPlanDAO> actionPlans = new List <ActionPlanDAO>(); var actionPlanFire = new ActionPlanDAO() { Id = "e768ab86-64d4-42e0-bd8a-9f012f774bbf", Name = "Fire", Description = "Pre-configured action plan for a fire", IsActive = true, Color = "red", Icon = "fire", PrimaryRadius = 1, SecondaryRadius = 2, AcceptSafeStatus = true, OpenActions = new List <ActionDAOObject>() { GenerateEmergencyCallMessage(), GenerateNotificationMessage("A fire has been detected in the area. If you are inside, listen for alarms instructing you to go outside."), GenerateActionPrimaryLightMessage("red"), GenerateActionSecondaryLightMessage("yellow") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("The fire has been contained. Safe to proceed as directed by authorities on the ground."), GenerateActionPrimaryLightMessage("off"), GenerateActionSecondaryLightMessage("off") } }; var actionPlanActiveShooter = new ActionPlanDAO() { Id = "32d4bc56-3c39-4000-9355-c08068a2ba1a", Name = "Active Shooter", Description = "Pre-configured action plan for an active shooter", IsActive = true, Color = "red", Icon = "gun", PrimaryRadius = 2, SecondaryRadius = 3, AcceptSafeStatus = true, OpenActions = new List <ActionDAOObject>() { GenerateEmergencyCallMessage(), GenerateNotificationMessage("Active Shooter in the area. Proceed with action plan immediately."), GenerateActionPrimaryLightMessage("red"), GenerateActionSecondaryLightMessage("yellow") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("Active Shooter situation ended. More info to come."), GenerateActionPrimaryLightMessage("off"), GenerateActionSecondaryLightMessage("off") } }; var actionPlanAirQuality = new ActionPlanDAO() { Id = "5524c361-540f-424f-8a56-23165fb515c6", Name = "Air Quality", Description = "Pre-configured action plan for an air quality", IsActive = true, Color = "yellow", Icon = "pollution", PrimaryRadius = 1, SecondaryRadius = 2, AcceptSafeStatus = true, OpenActions = new List <ActionDAOObject>() { GenerateNotificationMessage("Air Quality issues have been reported in the area.") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("Air Quality issues in the area have improved.") } }; var actionPlanHealthCheck = new ActionPlanDAO() { Id = "9ffe839c-1341-4a3b-9d33-bafd5e6cf407", Name = "Health Check", Description = "Pre-configured action plan for a health check", IsActive = true, Color = "blue", Icon = "health", PrimaryRadius = 1, SecondaryRadius = 2, AcceptSafeStatus = true, OpenActions = new List <ActionDAOObject>() { GenerateNotificationMessage("Health Check Activated.") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("Health Check Deactivated.") } }; var actionPlanActiveProtest = new ActionPlanDAO() { Id = "a79815c0-274a-4794-b7f0-175f9e48b257", Name = "Protest", Description = "Pre-configured action plan for a protest", IsActive = true, Color = "blue", Icon = "protest", PrimaryRadius = 1, SecondaryRadius = 2, AcceptSafeStatus = false, OpenActions = new List <ActionDAOObject>() { GenerateNotificationMessage("A planned protest will occur today in the area. Travel routes may be affected."), GenerateActionPrimaryLightMessage("red"), GenerateActionSecondaryLightMessage("yellow") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("The planned protest has concluded."), GenerateActionPrimaryLightMessage("off"), GenerateActionSecondaryLightMessage("off") } }; var actionPlanActiveSuspiciousPackage = new ActionPlanDAO() { Id = "c06d7a38-c51d-4e7f-9704-17686dd9f304", Name = "Suspicious Package", Description = "Pre-configured action plan for a suspicious package", IsActive = true, Color = "red", Icon = "package", PrimaryRadius = 1, SecondaryRadius = 2, AcceptSafeStatus = false, OpenActions = new List <ActionDAOObject>() { GenerateNotificationMessage("A suspicious package has been identified in the area. Authorities are on the way to assess it."), GenerateActionPrimaryLightMessage("red"), GenerateActionSecondaryLightMessage("yellow") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("The suspicious package has been cleared, the scene is safe."), GenerateActionPrimaryLightMessage("off"), GenerateActionSecondaryLightMessage("off") } }; var actionPlanActiveTornado = new ActionPlanDAO() { Id = "2cbcfb49-3348-4b49-878f-8cee71a18940", Name = "Tornado", Description = "Pre-configured action plan for a tornado", IsActive = true, Color = "yellow", Icon = "tornado", PrimaryRadius = 1, SecondaryRadius = 2, AcceptSafeStatus = true, OpenActions = new List <ActionDAOObject>() { GenerateNotificationMessage("A tornado watch is in effect for the area."), GenerateActionPrimaryLightMessage("red"), GenerateActionSecondaryLightMessage("yellow") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("The tornado watch has expired."), GenerateActionPrimaryLightMessage("off"), GenerateActionSecondaryLightMessage("off") } }; var actionPlanVIP = new ActionPlanDAO() { Id = "aff4de61-6f3d-45a2-9e27-81dda79a19e0", Name = "VIP", Description = "Pre-configured action plan for vip", IsActive = true, Color = "blue", Icon = "vip", PrimaryRadius = 1, SecondaryRadius = 2, AcceptSafeStatus = true, OpenActions = new List <ActionDAOObject>() { GenerateNotificationMessage("There is a planned appearance by a public figure in the area today. Travel routes may be affected.") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("The planned appearance by a public figure has concluded.") } }; var actionPlanActiveEmergency = new ActionPlanDAO() { Id = "0bbe4f8e-fe45-4c85-8d59-f4c3031823a5", Name = "Emergency", Description = "Pre-configured action plan for emergency", IsActive = true, Color = "red", Icon = "fire", PrimaryRadius = 2, SecondaryRadius = 3, AcceptSafeStatus = true, OpenActions = new List <ActionDAOObject>() { GenerateEmergencyCallMessage(), GenerateNotificationMessage("Emergency."), GenerateActionPrimaryLightMessage("red"), GenerateActionSecondaryLightMessage("yellow") }, CloseActions = new List <ActionDAOObject>() { GenerateNotificationMessage("End of emergency."), GenerateActionPrimaryLightMessage("off"), GenerateActionSecondaryLightMessage("off") } }; actionPlans.Add(actionPlanFire); actionPlans.Add(actionPlanActiveShooter); actionPlans.Add(actionPlanAirQuality); actionPlans.Add(actionPlanHealthCheck); actionPlans.Add(actionPlanActiveProtest); actionPlans.Add(actionPlanActiveSuspiciousPackage); actionPlans.Add(actionPlanActiveTornado); actionPlans.Add(actionPlanVIP); actionPlans.Add(actionPlanActiveEmergency); return(actionPlans); }