public ActionResult UserAppRole() { try { string userId = base.ValidateUser(); if (string.IsNullOrWhiteSpace(userId)) { return(RedirectToAction("LogOn", "Account")); } else { UserService us = new UserService(); Dictionary <string, object> criteria = new Dictionary <string, object>(); Dictionary <long, IList <Application> > appcode = us.GetApplicationListWithPagingAndCriteria(0, 9999, string.Empty, string.Empty, criteria); Dictionary <long, IList <Role> > rolecode = us.GetRoleListWithPagingAndCriteria(0, 9999, string.Empty, string.Empty, criteria); //var usrcmp = Session["SectorCode"] as IEnumerable<string>; //if (usrcmp.First() != null) // to check if the usrcmp obj is null or with data //{ // criteria.Add("Name", usrcmp); //} MastersService ms = new MastersService(); criteria.Clear(); ViewBag.appcodeddl = appcode.First().Value; ViewBag.rolecodeddl = rolecode.First().Value; return(View()); } } catch (Exception ex) { throw ex; } }
//from local SQL public async Task GetListMastersLocalSql(ListBox lb) { lb.Items.Clear(); List <Master> listmasters = null; try { mastersService = FactorySingleton.Factory.Get <MastersService>(); listmasters = (await mastersService.GetSQLPairedMasters()).ToList(); } catch (Exception e) { var err = e.Message; } if (listmasters != null && listmasters.Count != 0) { foreach (var master in listmasters) { lb.Items.Add(string.Format("{0} - ({1}) codeB = {2}", master.Name, master.TypeName, master.codeB)); } await UpdateOrCreateMastersToSql(listmasters); } else { lb.Items.Add("No pair masters!"); } }
private async Task UpdateOrCreateMastersToSql(IEnumerable <Master> codeResponce) { try { mastersService = FactorySingleton.Factory.Get <MastersService>(); await mastersService.SaveMastersToSql(codeResponce); } catch (Exception e) { var err = e.Message; } }
public void SendEmailNotification(TicketSystem objTcktSys, string userid, string activityName, bool?isrejction, string MailBody) { try { // IList<CampusEmailId> campusemaildet = GetEmailIdByCampus(objTcktSys.BranchCode, ConfigurationManager.AppSettings["CampusEmailType"].ToString()); bool rejection = isrejction ?? true;// false; UserService us = new UserService(); Dictionary <long, IList <UserAppRole> > userAppRole = new Dictionary <long, IList <UserAppRole> >(); Dictionary <string, object> criteriaUserAppRole = new Dictionary <string, object>(); //Based on activity need to assign the role to get the users //logic need to be written criteriaUserAppRole.Add("IsActive", true); //criteriaUserAppRole.Add("AppCode", "TKT"); //if (activityName == "LogETicket" || activityName == "ResolveETicketRejection" || activityName == "CloseETicket") //{ // criteriaUserAppRole.Add("RoleCode", "ETR"); //} //else if (activityName == "ResolveETicket" || activityName == "CloseETicketRejection") //{ criteriaUserAppRole.Add("RoleCode", "ETC"); } //else return; criteriaUserAppRole.Add("AppCode", new string[] { "TKT", "All" }); if (activityName == "LogETicket" || activityName == "ResolveETicketRejection" || activityName == "CloseETicket") { criteriaUserAppRole.Add("RoleCode", new string[] { "ETR", "All" }); } else if (activityName == "ResolveETicket" || activityName == "CloseETicketRejection") { criteriaUserAppRole.Add("RoleCode", new string[] { "ETC", "All" }); } else { return; } userAppRole = us.GetRoleUsersListWithPagingAndCriteria(0, 1000, string.Empty, string.Empty, criteriaUserAppRole); //if list userAppRole is null then empty grid if (userAppRole != null && userAppRole.Count > 0 && userAppRole.First().Key > 0) { int count = userAppRole.First().Value.Count; //if it has values then for each concatenate APP+ROLE string[] userEmails = new string[count]; int i = 0; Dictionary <string, object> criteria = new Dictionary <string, object>(); string[] userToEmail = (from u in userAppRole.FirstOrDefault().Value where u.AppCode != "All" && !string.IsNullOrEmpty(u.Email) select u.Email).ToArray(); string[] userBccEmail = (from u in userAppRole.FirstOrDefault().Value where u.AppCode == "All" && !string.IsNullOrEmpty(u.Email) select u.Email).ToArray(); //foreach (UserAppRole uar in userAppRole.First().Value) //{ // if (!string.IsNullOrWhiteSpace(uar.Email)) // { // userEmails[i] = uar.Email.Trim(); // } // i++; //} if (userToEmail == null || (userToEmail[0] == null && userToEmail.Length == 0)) { return; } if (userToEmail != null && userToEmail.Length > 0) { string SendEmail = ConfigurationManager.AppSettings["SendEmailOption"]; string From = ConfigurationManager.AppSettings["From"]; if (SendEmail == "false") { return; } else { try { System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.Subject = "e-Ticket Notification" + objTcktSys.TicketNo + " "; string msg = ""; foreach (string s in userToEmail) { if (!string.IsNullOrWhiteSpace(s)) { bool IsValid = IsValidEmail(s); if (IsValid == true) { mail.To.Add(s); } } } if (userBccEmail != null && userBccEmail.Length > 0) { foreach (string s in userBccEmail) { if (!string.IsNullOrWhiteSpace(s)) { bool IsValid = IsValidEmail(s); if (IsValid == true) { mail.Bcc.Add(s); } } } } switch (activityName) { case "LogETicket": { msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Logged for the module " + objTcktSys.Module + " with " + objTcktSys.Priority + " priority. The e-Ticket is Raised by " + userid + ". Please try resolving the ticket based on Priority. The summary of the ticket is <b><i>\"" + objTcktSys.Summary + "\"</i></b> "; break; } case "ResolveETicket": { if (rejection) { msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Rejected for the module " + objTcktSys.Module + ". The e-Ticket is Rejected for additional information by " + userid + ". Please try replying the same based on the comments.<b><i>\"" + ShowComments(objTcktSys.Id, userid, "ResolveETicket", "Rejection", objTcktSys.TicketNo) + "\"</i></b>"; msg = msg + CommentSummary(objTcktSys.Id, userid, "ResolveETicket", "Rejection", objTcktSys.TicketNo); } else { msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Resolved for the module " + objTcktSys.Module + ". The e-Ticket is Resolved by " + userid + " with comments <b><i>\"" + ShowComments(objTcktSys.Id, userid, "ResolveETicket", "Resolution", objTcktSys.TicketNo) + "\"</i></b>. Please verify the same and complete/Reject based on the results. "; msg = msg + CommentSummary(objTcktSys.Id, userid, "ResolveETicket", "Rejection", objTcktSys.TicketNo); } break; } case "ResolveETicketRejection": { msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Replied for the module " + objTcktSys.Module + ".by " + userid + " with Comments. <b><i>\"" + ShowComments(objTcktSys.Id, userid, "ResolveETicketRejection", "Resolution", objTcktSys.TicketNo) + "\"</i></b>. Please try resolving the same based on the reply comments. "; msg = msg + CommentSummary(objTcktSys.Id, userid, "ResolveETicket", "Rejection", objTcktSys.TicketNo); break; } case "CloseETicketRejection": { if (rejection) { msg += ""; } else { msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Rejected for the module " + objTcktSys.Module + ". The e-Ticket is Rejected by " + userid + " <b><i>\"" + ShowComments(objTcktSys.Id, userid, "CloseETicketRejection", "Resolution", objTcktSys.TicketNo) + "\"</i></b>. Please try resolving the same based on the comments. "; msg = msg + CommentSummary(objTcktSys.Id, userid, "ResolveETicket", "Rejection", objTcktSys.TicketNo); } break; } case "CloseETicket": { if (rejection) { msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Rejected for the module " + objTcktSys.Module + ". The e-Ticket is Rejected for additionnal information by " + userid + " <b><i>\"" + ShowComments(objTcktSys.Id, userid, "CloseETicket", "Rejection", objTcktSys.TicketNo) + "\"</i></b>. Please try replying the same based on the comments. "; msg = msg + CommentSummary(objTcktSys.Id, userid, "ResolveETicket", "Rejection", objTcktSys.TicketNo); } //else msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Completed for the module " + objTcktSys.Module + ". The e-Ticket is Completed by " + userid + " with comments <b><i>\"" + objTcktSys.Comments + "\"</i></b> "; else { msg += "An e-Ticket " + objTcktSys.TicketNo + " has been Completed for the module " + objTcktSys.Module + ". The e-Ticket is Completed by " + userid + " with comments <b><i>\"" + ShowComments(objTcktSys.Id, userid, "CloseETicket", "Resolution", objTcktSys.TicketNo) + "\"</i></b> "; msg = msg + CommentSummary(objTcktSys.Id, userid, "ResolveETicket", "Rejection", objTcktSys.TicketNo); } break; } default: return; } MailBody = MailBody.Replace("{{DateTime}}", DateTime.Now.ToString()); MailBody = MailBody.Replace("{{Content}}", msg); //Body = Body.Replace("{{footer}}", footer); mail.Body = MailBody; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("localhost", 25); smtp.Host = "smtp.gmail.com"; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.EnableSsl = true; if (From == "live") { try { mail.From = new MailAddress("*****@*****.**"); smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "Spring@2k14"); smtp.Send(mail); } catch (Exception ex) { #region saveorupdate Errorlog OrdersService OrdSer = new OrdersService(); ErrorLog err = new ErrorLog(); err.Controller = "EmailHelper"; err.Action = "SendEmailNotification"; err.Err_Desc = ex.ToString(); err.CreatedDate = DateTime.Now; OrdSer.SaveOrUpdateErrorLog(err); #endregion if (ex.Message.Contains("quota")) { mail.From = new MailAddress("*****@*****.**"); smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "Ginger@27"); smtp.Send(mail); } else { mail.From = new MailAddress("*****@*****.**"); smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "JohnSGrasiasXcd"); smtp.Send(mail); } } } else if (From == "test") { mail.From = new MailAddress("*****@*****.**"); smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "Spring@2k14"); //this is to send email to test mail only to avoid mis communication to the parent // mail.To.Add("*****@*****.**"); smtp.Send(mail); } EmailLog el = new EmailLog(); el.Id = 0; el.EmailTo = mail.To.ToString(); el.EmailCC = mail.CC.ToString(); if (mail.Bcc.ToString().Length < 3990) { el.EmailBCC = mail.Bcc.ToString(); } el.Subject = mail.Subject.ToString(); if (mail.Body.ToString().Length < 3990) { el.Message = msg; } el.EmailDateTime = DateTime.Now; el.BCC_Count = mail.Bcc.Count; el.Module = "ETicket"; //create the admission management object MastersService msObj = new MastersService(); //log the email to the database msObj.CreateOrUpdateEmailLog(el); } catch (Exception ex) { #region saveorupdate Errorlog OrdersService OrdSer = new OrdersService(); ErrorLog err = new ErrorLog(); err.Controller = "EmailHelper"; err.Action = "SendEmailNotification"; err.Err_Desc = ex.ToString(); err.CreatedDate = DateTime.Now; OrdSer.SaveOrUpdateErrorLog(err); #endregion throw ex; } } } } } catch (Exception ex) { #region saveorupdate Errorlog OrdersService OrdSer = new OrdersService(); ErrorLog err = new ErrorLog(); err.Controller = "EmailHelper"; err.Action = "SendEmailNotification"; err.Err_Desc = ex.ToString(); err.CreatedDate = DateTime.Now; OrdSer.SaveOrUpdateErrorLog(err); #endregion ExceptionPolicy.HandleException(ex, "TicketingSystem"); throw ex; } }