public ActionResult WorkList() { ManageTrainingModel AsgnList = new ManageTrainingModel(); Session["ServerName"] = AppValue.GetFromMailAddress("ServerName"); try { int UserId = int.Parse(Session["UserID"].ToString()); DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1(); AsgnList.CompletionResult = (from rc in db.Trainings join l in db.Master_TrainingLevel on rc.LevelId equals l.LevelId join t in db.Master_TrainingTechnology on rc.TechnologyId equals t.TechnologyId join i in db.Users on rc.InstructorId equals i.UserID join n in db.TrainingNominations on rc.TrainingId equals n.TrainingId //join c in db.TrainingCompletions on rc.TrainingId equals c.TrainingId //where rc.IsActive == true && rc.InstructorId == UserId && n.Score == 0 && n.CompletionFlag==true && EntityFunctions.TruncateTime(rc.ScheduledDate) <= DateTime.Today.Date where rc.IsActive == true && rc.InstructorId == UserId && EntityFunctions.TruncateTime(rc.ScheduledDate) <= DateTime.Today.Date select new CompletionResultModel() { TrainingID = rc.TrainingId, TrainingName = rc.TrainingName, Technology = t.TechnologyName, ScheduledDate = rc.ScheduledDate, IsCompleted = n.CompletionFlag, Instructor = ((i.FirstName.Length > 0 ? i.FirstName : "") + " " + (i.LastName.Length > 0 ? i.LastName : "")), Starttime = rc.StartTime, submit = db.TrainingFeedBackCalcs.Where(x => x.TrainingId == rc.TrainingId && x.Flag == true).Count(), pending = db.TrainingFeedBackCalcs.Where(x => x.TrainingId == rc.TrainingId && x.Flag == false).Count(), Endtime = rc.EndTime, Nominations = rc.NumberOfNominated, //Attendees = (int)rc.NumberOfNominated }).Distinct().ToList(); AsgnList.FeedBackResult = (from rc in db.Trainings join f in db.TrainingFeedBackCalcs on rc.TrainingId equals f.TrainingId where f.Flag == false && rc.IsActive == true && f.UserId == UserId && EntityFunctions.TruncateTime(rc.ScheduledDate) <= DateTime.Today.Date //&& EntityFunctions.TruncateTime(EntityFunctions.AddDays(f.FeedBackSentOn, 3)) >= DateTime.Today.Date select new FeedBackResultModel() { TrainingID = rc.TrainingId, TrainingName = rc.TrainingName }).Distinct().ToList(); } catch (Exception Ex) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName); } return(View(AsgnList)); }
public ActionResult Delete(int TrainingID) { DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1(); ManageTrainingModel model = new ManageTrainingModel(); string ServerName = AppValue.GetFromMailAddress("ServerName"); var obj = db.Trainings.Where(x => x.TrainingId == TrainingID).FirstOrDefault(); obj.IsActive = false; obj.StatusId = 5; var val = db.TrainingNominations.Where(x => x.TrainingId == TrainingID).Select(o => o).ToList(); foreach (var item in val) { item.IsActive = false; db.SaveChanges(); } db.SaveChanges(); var MailPurposeObj = db.TrainingMailPurposes.Where(x => x.TrainingId == TrainingID).FirstOrDefault(); MailPurposeObj.IsActive = false; db.SaveChanges(); string Tid = obj.TrainingId.ToString(); string tname = obj.TrainingName; DateTime d1 = Convert.ToDateTime(obj.ScheduledDate); string d = d1.ToShortDateString(); string stime = obj.StartTime; string etime = obj.EndTime; var userref = db.Users.FirstOrDefault(o => o.UserID == obj.InstructorId); string username = userref.FirstName + userref.LastName; List <string> MailID = new List <string>(); MailID.Add(userref.EmailAddress); var EmpIDList = db.TrainingNominations.Where(o => o.TrainingId == obj.TrainingId).Select(o => o.EmpId).ToList(); foreach (string Eid in EmpIDList) { model.EmpID = Eid.ToString(); model.EmpID = "0" + model.EmpID; model.MailAddress = db.Users.FirstOrDefault(o => o.EmpID == model.EmpID).EmailAddress; MailID.Add(model.MailAddress); } // string mailMessage = MailBuilder.TrainingScheduleCancelled(Tid, tname, d, stime, etime, username); var check = db.EmailTemplates.Where(x => x.TemplatePurpose == "Training Schedule Cancelled").Select(o => o.EmailTemplateID).FirstOrDefault(); var folder = db.EmailTemplates.Where(o => o.TemplatePurpose == "Training Schedule Cancelled").Select(x => x.TemplatePath).FirstOrDefault(); if ((check != null) && (check != 0)) { var objTrainingScheduleCancelled = (from p in db.EmailPurposes.Where(x => x.EmailPurposeName == "Training Schedule Cancelled") join q in db.EmailTemplates on p.EmailTemplateID equals q.EmailTemplateID select new DSRCManagementSystem.Models.Email { To = p.To, CC = p.CC, BCC = p.BCC, Subject = p.Subject, Template = q.TemplatePath }).FirstOrDefault(); var objcom = db.Master_ApplicationSettings.Where(x => x.AppKey == "Company Name").Select(o => o.AppValue).FirstOrDefault(); string TemplatePathTrainingScheduleCancelled = Server.MapPath(objTrainingScheduleCancelled.Template); string htmlTrainingScheduleCancelled = System.IO.File.ReadAllText(TemplatePathTrainingScheduleCancelled); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#TrainingId", Tid); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#TrainingName", tname); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#ScheduledDate", d); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#start", stime); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#end", etime); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#Instructor", username); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#ServerName", ServerName); htmlTrainingScheduleCancelled = htmlTrainingScheduleCancelled.Replace("#ComapanyName", objcom); //string ServerName = WebConfigurationManager.AppSettings["SeverName"]; var logo = CommonLogic.getLogoPath(); if (ServerName != "http://*****:*****@dsrc.co.in"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); string EmailAddress = ""; foreach (string mail in MailIds) { EmailAddress += mail + ","; } EmailAddress = EmailAddress.Remove(EmailAddress.Length - 1); //var logo = db.Master_ApplicationSettings.Where(x => x.AppID == 7).Select(x => x).FirstOrDefault(); // DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleCancelled.Subject + " - Test Mail Please Ignore", null, htmlTrainingScheduleCancelled + " - Testing Plaese ignore", "*****@*****.**", EmailAddress, Server.MapPath(logo.AppValue.ToString())); DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleCancelled.Subject + " - Test Mail Please Ignore", null, htmlTrainingScheduleCancelled + " - Testing Plaese ignore", "*****@*****.**", EmailAddress, Server.MapPath(logo.ToString())); } else { foreach (string mail in MailID) { //Task.Factory.StartNew(() => //{ //var logo = db.Master_ApplicationSettings.Where(x => x.AppID == 7).Select(x => x).FirstOrDefault(); // DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleCancelled.Subject, null, htmlTrainingScheduleCancelled, "*****@*****.**", mail, Server.MapPath(logo.AppValue.ToString())); DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleCancelled.Subject, null, htmlTrainingScheduleCancelled, "*****@*****.**", mail, Server.MapPath(logo.ToString())); //DsrcMailSystem.MailSender.LDSendMail(null, "L & D - Training Schedule Cancelled", null, mailMessage, "*****@*****.**", mail, Server.MapPath("~/Content/Template/images/logo.png")); // }); } } } else { //string ServerName = WebConfigurationManager.AppSettings["SeverName"]; ExceptionHandlingController.TemplateMissing("Training Schedule Cancelled", folder, ServerName); } return(Json("Success", JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(ManageTrainingModel model) { string ServerName = AppValue.GetFromMailAddress("ServerName"); using (DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1()) { var obj_Comp = db.Trainings.FirstOrDefault(o => o.TrainingId == model.TrainingID); if (obj_Comp.ScheduledDate != model.ScheduledDate || obj_Comp.StartTime != model.Starttime || obj_Comp.EndTime != model.Endtime || obj_Comp.SeatingCapacity != model.SeatingCapacity) { var Message = ""; LDCourse1Controller obj = new LDCourse1Controller(); int ID = Convert.ToInt32(model.TrainingID); string dt = model.ScheduledDate.ToString(); string time = Convert.ToString(model.Starttime); string endtime = Convert.ToString(model.Endtime); var message = obj.scheduletime(ID, dt, model.TrainingName, time, endtime); Message = Convert.ToString(message.Data); if (Message == "availabletime") { return(Json(Message, JsonRequestBehavior.AllowGet)); } obj_Comp.SeatingCapacity = model.SeatingCapacity; obj_Comp.ScheduledDate = model.ScheduledDate; obj_Comp.StartTime = model.Starttime; obj_Comp.EndTime = model.Endtime; obj_Comp.StatusId = 7; db.SaveChanges(); string Tid = obj_Comp.TrainingId.ToString(); string tname = obj_Comp.TrainingName; DateTime d1 = Convert.ToDateTime(model.ScheduledDate); string d = d1.ToShortDateString(); string stime = obj_Comp.StartTime; string etime = obj_Comp.EndTime; var userref = db.Users.FirstOrDefault(o => o.UserID == obj_Comp.InstructorId); string username = userref.FirstName + " " + (userref.LastName ?? ""); List <string> MailID = new List <string>(); MailID.Add(userref.EmailAddress); var EmpIDList = db.TrainingNominations.Where(o => o.TrainingId == model.TrainingID).Select(o => o.EmpId).ToList(); //foreach (int Eid in EmpIDList) foreach (string Eid in EmpIDList) { model.EmpID = Eid.ToString(); if (model.EmpID.Length == 4) { model.EmpID = "0" + model.EmpID; } model.MailAddress = db.Users.FirstOrDefault(o => o.EmpID == model.EmpID).EmailAddress ?? ""; MailID.Add(model.MailAddress); } //string mailMessage = MailBuilder.TrainingScheduleChangeNotification(Tid, tname, d, stime, etime, username); var check = db.EmailTemplates.Where(x => x.TemplatePurpose == "Training Schedule Change Notification").Select(o => o.EmailTemplateID).FirstOrDefault(); var folder = db.EmailTemplates.Where(o => o.TemplatePurpose == "Training Schedule Change Notification").Select(x => x.TemplatePath).FirstOrDefault(); if ((check != null) && (check != 0)) { var objTrainingScheduleChangeNotification = (from p in db.EmailPurposes.Where(x => x.EmailPurposeName == "Training Schedule Change Notification") join q in db.EmailTemplates on p.EmailTemplateID equals q.EmailTemplateID select new DSRCManagementSystem.Models.Email { To = p.To, CC = p.CC, BCC = p.BCC, Subject = p.Subject, Template = q.TemplatePath }).FirstOrDefault(); var objcom = db.Master_ApplicationSettings.Where(x => x.AppKey == "Company Name").Select(o => o.AppValue).FirstOrDefault(); string TemplatePathTrainingScheduleChangeNotification = Server.MapPath(objTrainingScheduleChangeNotification.Template); string htmlTrainingScheduleChangeNotification = System.IO.File.ReadAllText(TemplatePathTrainingScheduleChangeNotification); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#TrainingId", Tid); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#TrainingName", tname); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#ScheduledDate", d); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#start", stime); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#end", etime); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#Instructor", username); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#CompanyName", objcom); htmlTrainingScheduleChangeNotification = htmlTrainingScheduleChangeNotification.Replace("#ServerName", ServerName); //string ServerName = WebConfigurationManager.AppSettings["SeverName"]; var logo = CommonLogic.getLogoPath(); if (ServerName != "http://*****:*****@dsrc.co.in"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); //MailIds.Add("*****@*****.**"); string EmailAddress = ""; foreach (string mail in MailIds) { EmailAddress += mail + ","; } EmailAddress = EmailAddress.Remove(EmailAddress.Length - 1); //var logo = db.Master_ApplicationSettings.Where(x => x.AppID == 7).Select(x => x).FirstOrDefault(); // DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleChangeNotification.Subject + " - Test Mail Please Ignore", null, htmlTrainingScheduleChangeNotification + " - Testing Plaese ignore", "*****@*****.**", EmailAddress, Server.MapPath(logo.AppValue.ToString())); DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleChangeNotification.Subject + " - Test Mail Please Ignore", null, htmlTrainingScheduleChangeNotification + " - Testing Plaese ignore", "*****@*****.**", EmailAddress, Server.MapPath(logo.ToString())); } else { foreach (string mail in MailID) { //var logo = db.Master_ApplicationSettings.Where(x => x.AppID == 7).Select(x => x).FirstOrDefault(); //DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleChangeNotification.Subject, null, htmlTrainingScheduleChangeNotification, "*****@*****.**", mail, Server.MapPath(logo.AppValue.ToString())); DsrcMailSystem.MailSender.SendMail(null, objTrainingScheduleChangeNotification.Subject, null, htmlTrainingScheduleChangeNotification, "*****@*****.**", mail, Server.MapPath(logo.ToString())); } } } else { //string ServerName = WebConfigurationManager.AppSettings["SeverName"]; ExceptionHandlingController.TemplateMissing("Training Schedule Change Notification", folder, ServerName); } } return(Json("Success", JsonRequestBehavior.AllowGet)); } }