private void SendUserAllocationEmailsToLevel1Departments(long groupNumber) { try { logger.DebugFormat("Sending User Allocation Email to departments by GroupNumber [{0}]", groupNumber); var userAllocation = userAllocationManagement.GetUserAllocationsByGroupNumber(groupNumber); if (userAllocation == null) { logger.DebugFormat("No Allocation Found With Group Number [{0}]", groupNumber); return; } else if (userAllocation.Count() == 0) { logger.DebugFormat("No Allocation Found With Group Number [{0}]", groupNumber); return; } UserAllocationEmailVM emailVM = new UserAllocationEmailVM(); string styleSheet = System.IO.File.ReadAllText(Server.MapPath("~/Themes/finance-1/css/emailstyle.css")); emailVM.StyleSheet = styleSheet; emailVM.UserAllocations = userAllocation; var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/EmailTemplates/UserAllocationEmailToDepartments.cshtml")); string template = System.IO.File.ReadAllText(viewsPath); string uniqueNumber = Guid.NewGuid().ToString(); string body = Engine.Razor.RunCompile(template, string.Format("UserAllocationEmail_{0}", uniqueNumber), typeof(UserAllocationEmailVM), emailVM); var role = RoleManager.Roles.Where(x => x.Name.Equals(UserRoles.Manager)).FirstOrDefault(); if (userAllocation != null && userAllocation.Count() > 0) { foreach (var allocation in userAllocation) { var departManagers = userManagement.GetAllUsersByRoleAndDepartment(role.Id, allocation.DepartmentID); if (departManagers != null && departManagers.Count() > 0) { foreach (var user in departManagers) { ICommunicationManagement comManagement = new CommunicationManagement(); comManagement.Subject = string.Format("User Re Allocation Request "); comManagement.Body = body; comManagement.Recipient = user.Email; comManagement.HeaderImage = Server.MapPath("~/Themes/finance-1/img/logo.png"); Async.Do(() => comManagement.SendEmail()); logger.DebugFormat("Email Successfully Send"); } } } } } catch (Exception ex) { logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace); } }
private void SendRequisitionEmailsToLevel2Department(long requisitionId) { try { logger.DebugFormat("Sending Requisition Email to level 2 departments by RequisitionID [{0}]", requisitionId); RequisitionVM req = requisitionManagement.GetRequisitionCompleteInfoById(requisitionId); if (req == null) { logger.DebugFormat("No Requisition Found With ID [{0}]", requisitionId); return; } string styleSheet = System.IO.File.ReadAllText(Server.MapPath("~/Themes/finance-1/css/emailstyle.css")); req.StyleSheet = styleSheet; var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/EmailTemplates/RequisitionEmailToDepartments.cshtml")); string template = System.IO.File.ReadAllText(viewsPath); string uniqueNumber = Guid.NewGuid().ToString(); string body = Engine.Razor.RunCompile(template, string.Format("RequisitionEmail_{0}", uniqueNumber), typeof(UserTaskEmailVM), req); var role = RoleManager.Roles.Where(x => x.Name.Equals(UserRoles.Manager)).FirstOrDefault(); var requisitionApprovalDepartments = requisitionApprovalManagement.GetAllRequisitionApprovalByRequisition(req.RequisitionID); if (requisitionApprovalDepartments != null && requisitionApprovalDepartments.Count() > 0) { foreach (var approvalDept in requisitionApprovalDepartments) { var departManagers = userManagement.GetAllUsersByRoleAndDepartment(role.Id, approvalDept.DepartmentID); if (departManagers != null && departManagers.Count() > 0) { foreach (var user in departManagers) { ICommunicationManagement comManagement = new CommunicationManagement(); comManagement.Subject = string.Format("New Requisition Request #. {0} - {1} ", Utility.FormatedId("UR-", req.RequisitionID.ToString()), req.JobTitle); comManagement.Body = body; comManagement.Recipient = user.Email; comManagement.HeaderImage = Server.MapPath("~/Themes/finance-1/img/logo.png"); Async.Do(() => comManagement.SendEmail()); logger.DebugFormat("Email Successfully Send"); } } } } } catch (Exception ex) { logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace); } }
private void SendUserAllocationEmailsToRequestCreator(long groupNumber, string status, string comments) { try { logger.DebugFormat("Sending User Allocation Email to request creator by GroupNumber [{0}]", groupNumber); var userAllocation = userAllocationManagement.GetUserAllocationsByGroupNumber(groupNumber); if (userAllocation == null) { logger.DebugFormat("No Allocation Found With Group Number [{0}]", groupNumber); return; } else if (userAllocation.Count() == 0) { logger.DebugFormat("No Allocation Found With Group Number [{0}]", groupNumber); return; } UserAllocationEmailVM emailVM = new UserAllocationEmailVM(); string styleSheet = System.IO.File.ReadAllText(Server.MapPath("~/Themes/finance-1/css/emailstyle.css")); emailVM.StyleSheet = styleSheet; emailVM.UserAllocations = userAllocation; emailVM.Status = status; emailVM.Comments = comments; var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/EmailTemplates/UserAllocationEmailToRequestCreator.cshtml")); string template = System.IO.File.ReadAllText(viewsPath); string uniqueNumber = Guid.NewGuid().ToString(); string body = Engine.Razor.RunCompile(template, string.Format("UserAllocationEmail_{0}", uniqueNumber), typeof(UserAllocationEmailVM), emailVM); var user = UserManager.FindById(userAllocation[0].CreatedBy.ToString()); if (user != null) { ICommunicationManagement comManagement = new CommunicationManagement(); comManagement.Subject = string.Format("User Re-Allocation Request Status"); comManagement.Body = body; comManagement.Recipient = user.Email; comManagement.HeaderImage = Server.MapPath("~/Themes/finance-1/img/logo.png"); Async.Do(() => comManagement.SendEmail()); logger.DebugFormat("Email Successfully Send"); } } catch (Exception ex) { logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace); } }
private void RequisitionStatusEmailToUser(long requisitionId, string status, string comments) { try { logger.DebugFormat("Sending Requisition Email to request creator by RequisitionID [{0}]", requisitionId); RequisitionVM req = requisitionManagement.GetRequisitionCompleteInfoById(requisitionId); if (req == null) { logger.DebugFormat("No Requisition Found With ID [{0}]", requisitionId); return; } string styleSheet = System.IO.File.ReadAllText(Server.MapPath("~/Themes/finance-1/css/emailstyle.css")); req.StyleSheet = styleSheet; req.Status = status; req.Comments = comments; var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/EmailTemplates/RequisitionEmailToRequestCreator.cshtml")); string template = System.IO.File.ReadAllText(viewsPath); string uniqueNumber = Guid.NewGuid().ToString(); string body = Engine.Razor.RunCompile(template, string.Format("RequisitionEmail_{0}", uniqueNumber), typeof(UserTaskEmailVM), req); var role = RoleManager.Roles.Where(x => x.Name.Equals(UserRoles.Manager)).FirstOrDefault(); var user = UserManager.FindById(req.CreatedBy.ToString()); if (user != null) { ICommunicationManagement comManagement = new CommunicationManagement(); comManagement.Subject = string.Format("Requisition Request #. {0} Status - {1} ", Utility.FormatedId("UR-", req.RequisitionID.ToString()), req.Status); comManagement.Body = body; comManagement.Recipient = user.Email; comManagement.HeaderImage = Server.MapPath("~/Themes/finance-1/img/logo.png"); Async.Do(() => comManagement.SendEmail()); logger.DebugFormat("Email Successfully Send"); } } catch (Exception ex) { logger.ErrorFormat("Exception Raised : Message[{0}] Stack Trace [{1}] ", ex.Message, ex.StackTrace); } }