public IActionResult SendCCee(string p1) { try { var f = Request.Query["studentId"]; var sDetail = ImmediateDB.StudentDetail.Where(i => i.RefNo == "").SingleOrDefault(); var sentEmailControl = ImmediateDB.CcsentMailControl.Where(i => i.StudentDetailId == sDetail.StudentDetailId).SingleOrDefault(); if (sentEmailControl == null) { sentEmailControl = new CcsentMailControl() { StudentDetailId = sDetail.StudentDetailId, DateSent = DateTime.Now, Receipiant = sDetail.Email, Attempts = 1 }; ImmediateDB.Add(sentEmailControl); } else { sentEmailControl.Attempts++; sentEmailControl.DateSent = DateTime.Now; ImmediateDB.Update(sentEmailControl); } ImmediateDB.SaveChanges(); var appCredential = ImmediateDB.AppCredentials.Where(i => i.IdentityKey == sDetail.StudentDetailId.ToString() && i.SystemRef == "CC").SingleOrDefault(); if (appCredential == null) { appCredential = new AppCredentials() { ActivationWord = getRandString(50), IdentityKey = sDetail.StudentDetailId.ToString(), Expiry = null, SystemRef = "CC", ProtectionString = getRandString(10) }; ImmediateDB.Add(appCredential); } else { } ImmediateDB.SaveChanges(); var dispQueue = ImmediateDB.CcdispatchQueue.Where(i => i.StudentDetailId == sDetail.StudentDetailId).SingleOrDefault(); if (dispQueue == null) { dispQueue = new CcdispatchQueue() { StudentDetailId = sDetail.StudentDetailId, AddedBy = "", DateStamp = DateTime.Now, Status = 0 }; ImmediateDB.Add(dispQueue); } else { dispQueue.DateStamp = DateTime.Now; dispQueue.Status = 0; ImmediateDB.Update(dispQueue); } ImmediateDB.SaveChanges(); return(View()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult SendCC([FromQuery] int studentDetailId) { Log.Information($"Sending CC email to {studentDetailId}"); string username = User.Identity.Name.Split('\\')[User.Identity.Name.Split('\\').Length - 1]; var CCPermission = Context.ProSolutionPermissions.Where(i => i.UserName == username && i.IsAllowed == true && i.ObjectName == Config["CCProSolutionSecurityObject:ObjectName"] && i.ActionName == Config["CCProSolutionSecurityObject:ActionName"] && i.ObjectType == Config["CCProSolutionSecurityObject:ObjectType"]).FirstOrDefault(); var harrogateLetterPermission = Context.ProSolutionPermissions.Where(i => i.UserName == username && i.IsAllowed == true && i.ObjectName == Config["HOfferProSolutionSecurityObject:ObjectName"] && i.ActionName == Config["HOfferProSolutionSecurityObject:ActionName"] && i.ObjectType == Config["HOfferProSolutionSecurityObject:ObjectType"]).FirstOrDefault(); var generalLetterPermission = Context.ProSolutionPermissions.Where(i => i.UserName == username && i.IsAllowed == true && i.ObjectName == Config["GOfferProSolutionSecurityObject:ObjectName"] && i.ActionName == Config["GOfferProSolutionSecurityObject:ActionName"] && i.ObjectType == Config["GOfferProSolutionSecurityObject:ObjectType"]).FirstOrDefault(); StudentDetail student = Context.StudentDetail.Where(i => i.StudentDetailId == studentDetailId).SingleOrDefault(); if (student == null) { ModelState.AddModelError("", "No Student specified - close this window and try again"); Log.Error("No Student specified"); return(View("Index", new StudentView())); } //var str = Request.Query["studentData"].FirstOrDefault(); var sDetail = Context.StudentDetail.Where(i => i.StudentDetailId == studentDetailId).SingleOrDefault(); try { if (sDetail.CriminalConvictionId != 2) { ModelState.AddModelError("", $"Student {sDetail.RefNo} does not have a criminal conviction"); return(View("Index", MapStudentView(sDetail, true, CCPermission != null, harrogateLetterPermission != null, generalLetterPermission != null))); } var sentEmailControl = Context.CcsentMailControl.Where(i => i.StudentDetailId == sDetail.StudentDetailId).SingleOrDefault(); if (sentEmailControl == null) { sentEmailControl = new CcsentMailControl() { StudentDetailId = sDetail.StudentDetailId, DateSent = DateTime.Now, Receipiant = sDetail.Email, Attempts = 1 }; Context.Add(sentEmailControl); } else { if (sentEmailControl.Attempts > 0) { sentEmailControl.Attempts++; } sentEmailControl.DateSent = DateTime.Now; Context.Update(sentEmailControl); } Context.SaveChanges(); var appCredential = Context.AppCredentials.Where(i => i.IdentityKey == sDetail.StudentDetailId.ToString() && i.SystemRef == "CC").SingleOrDefault(); if (appCredential == null) { appCredential = new AppCredentials() { ActivationWord = getRandString(50), IdentityKey = sDetail.StudentDetailId.ToString(), Expiry = null, SystemRef = "CC", ProtectionString = getRandString(10) }; Context.Add(appCredential); } else { } Context.SaveChanges(); var dispQueue = Context.CcdispatchQueue.Where(i => i.StudentDetailId == sDetail.StudentDetailId && i.SystemRef == "CC").SingleOrDefault(); if (dispQueue == null) { dispQueue = new CcdispatchQueue() { StudentDetailId = sDetail.StudentDetailId, AddedBy = User.Identity.Name, DateStamp = DateTime.Now, Status = 0, SystemRef = "CC" }; Context.Add(dispQueue); } else { dispQueue.DateStamp = DateTime.Now; dispQueue.AddedBy = User.Identity.Name; dispQueue.Status = 0; Context.Update(dispQueue); } Context.SaveChanges(); Log.Information($"Finished SendCC for {sDetail.RefNo} {ModelState.IsValid}"); if (!ModelState.IsValid) { foreach (var error in ModelState) { Log.Error($"{error}"); } } return(View("Index", MapStudentView(sDetail, true, CCPermission != null, harrogateLetterPermission != null, generalLetterPermission != null))); } catch (Exception ex) { ModelState.AddModelError("", "An error has occurred"); Log.Error(ex.Message); return(View("Index", MapStudentView(sDetail, true, CCPermission != null, harrogateLetterPermission != null, generalLetterPermission != null))); } }