public ActionResult Create(AddressCreationModel model) { if (!ModelState.IsValid) { return(View(model)); } try { TipstaffRecord tr = db.TipstaffRecord.Find(model.tipstaffRecordID); string controller = genericFunctions.TypeOfTipstaffRecord(tr); //do stuff tr.addresses.Add(model.address); db.SaveChanges(); if (Request.IsAjaxRequest()) { string url = string.Format("window.location='{0}';", Url.Action("Details", controller, new { id = model.tipstaffRecordID })); return(JavaScript(url)); } else { return(RedirectToAction("Details", controller, new { id = model.tipstaffRecordID })); } } catch (Exception ex) { _logger.LogError(ex, $"Exception in AddressController in Create method, for user {((CPrincipal)User).UserID}"); ErrorModel errModel = new ErrorModel(2); errModel.ErrorMessage = genericFunctions.GetLowestError(ex); TempData["ErrorModel"] = errModel; return(RedirectToAction("IndexByModel", "Error", errModel ?? null)); } }
public ActionResult Create(CaseReviewCreation model) { //do stuff to save CaseReview //Add event? if (ModelState.IsValid) { //if (genericFunctions.isTipstaffRecordChildAbduction){ TipstaffRecord tr = db.TipstaffRecord.Find(model.CaseReview.tipstaffRecordID); tr.caseReviews.Add(model.CaseReview); if (model.CaseReview.caseReviewStatusID == 2 || model.CaseReview.caseReviewStatusID == 3) { tr.caseStatusID = model.CaseReview.caseReviewStatusID + 1; } else { tr.caseStatusID = model.CaseStatusID; } if (model.CaseReview.nextReviewDate != null) { tr.nextReviewDate = model.CaseReview.nextReviewDate; } db.SaveChanges(); if (model.CaseReview.caseReviewStatusID == 2) { //user picked file closed, so get reasons... return(RedirectToAction("EnterResult", genericFunctions.TypeOfTipstaffRecord(tr), new { id = model.CaseReview.tipstaffRecordID })); } return(RedirectToAction("Details", genericFunctions.TypeOfTipstaffRecord(tr), new { id = model.CaseReview.tipstaffRecordID })); } return(View(model)); }
public ActionResult ChooseAddressee(int tipstaffRecordID, int templateID) { TipstaffRecord tr = db.TipstaffRecord.Find(tipstaffRecordID); if (tr.caseStatus.sequence > 3) { TempData["UID"] = tr.UniqueRecordID; return(RedirectToAction("ClosedFile", "Error")); } Template t = db.Templates.Find(templateID); if (t.addresseerequired) { ChooseAddresseeModel model = new ChooseAddresseeModel(); model.tipstaffRecord = tr; model.template = t; model.SolicitorsOnRecord = tr.LinkedSolicitors; if (genericFunctions.isTipstaffRecordChildAbduction(tr)) { model.Applicants = ((ChildAbduction)tr).Applicants; } return(View(model)); } else { return(RedirectToRoute(new { action = "Create", controller = "Template", tipstaffRecordID = tr.tipstaffRecordID, templateID = t.templateID })); } }
public ActionResult Upload(DocumentUploadModel model) { User user = db.GetUserByLoginName(User.Identity.Name.Split('\\').Last()); model.document.createdBy = user.DisplayName; model.document.createdOn = DateTime.Now; model.document.tipstaffRecordID = model.tipstaffRecordID; if (model.uploadFile != null) { var stream = model.uploadFile.InputStream; var buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); model.document.binaryFile = buffer; model.document.fileName = System.IO.Path.GetFileName(model.uploadFile.FileName); model.document.mimeType = model.uploadFile.ContentType; } if (ModelState.IsValid) { TipstaffRecord tr = db.TipstaffRecord.Find(model.tipstaffRecordID); tr.Documents.Add(model.document); db.SaveChanges(); return(RedirectToAction("Details", genericFunctions.TypeOfTipstaffRecord(tr), new { id = model.tipstaffRecordID })); } return(View(model)); }
public static string TypeOfTipstaffRecord(int id) { using (TipstaffDB tempDB = new TipstaffDB()) { TipstaffRecord obj = tempDB.TipstaffRecord.Find(id); return(isTipstaffRecordChildAbduction(obj) ? "ChildAbduction" : "Warrant"); } }
public PartialViewResult ListPoliceForcesByRecord(int id, int?page) { TipstaffRecord w = db.TipstaffRecord.Find(id); ListPoliceForcesByTipstaffRecord model = new ListPoliceForcesByTipstaffRecord(); model.tipstaffRecordID = w.tipstaffRecordID; model.PoliceForces = w.policeForces.OrderByDescending(d => d.policeForce.policeForceName).ToXPagedList <TipstaffPoliceForce>(page ?? 1, 8); return(PartialView("_ListPoliceForcesByRecord", model)); }
public PartialViewResult ListCaseReviewsByRecord(int id, int?page) { TipstaffRecord w = db.TipstaffRecord.Find(id); ListCaseReviewsByTipstaffRecord model = new ListCaseReviewsByTipstaffRecord(); model.tipstaffRecordID = w.tipstaffRecordID; model.CaseReviews = w.caseReviews.OrderByDescending(d => d.reviewDate).ToXPagedList <CaseReview>(page ?? 1, 8); return(PartialView("_ListCaseReviewsByRecord", model)); }
// // GET: /NPO/Add public ActionResult Add(int id) { TipstaffNPO model = new TipstaffNPO(); TipstaffRecord ts = db.TipstaffRecord.Find(id); model.tipstaffRecordID = id; model.UniqueRecordID = ts.UniqueRecordID; model.NPO = ts.NPO; return(View(model)); }
public PartialViewResult ListAttendanceNotesByRecord(int id, int?page) { TipstaffRecord w = db.TipstaffRecord.Find(id); ListAttendanceNotesByTipstaffRecord model = new ListAttendanceNotesByTipstaffRecord(); model.tipstaffRecordID = w.tipstaffRecordID; model.TipstaffRecordClosed = w.caseStatusID > 2; model.AttendanceNotes = w.AttendanceNotes.OrderByDescending(p => p.callDated).ToXPagedList <AttendanceNote>(page ?? 1, 8); return(PartialView("_ListAttendanceNotesByRecord", model)); }
public PartialViewResult ListDocumentsByRecord(int id, int?page) { TipstaffRecord w = db.TipstaffRecord.Find(id); ListDocumentsByTipstaffRecord model = new ListDocumentsByTipstaffRecord(); model.tipstaffRecordID = w.tipstaffRecordID; model.TipstaffRecordClosed = w.caseStatusID > 2; model.Documents = w.Documents.OrderByDescending(d => d.createdOn).ToXPagedList <Document>(page ?? 1, 8); return(PartialView("_ListDocumentsByRecord", model)); }
public PartialViewResult ListAddressesByRecord(int id, int?page) { TipstaffRecord w = db.TipstaffRecord.Find(id); ListAddressesByTipstaffRecord model = new ListAddressesByTipstaffRecord(); model.tipstaffRecordID = w.tipstaffRecordID; model.TipstaffRecordClosed = w.caseStatusID > 2; model.Addresses = w.addresses.ToXPagedList <Address>(page ?? 1, 8); //model.Addresses = w.addresses.ToPagedList<Address>(page ?? 1, 8); return(PartialView("_ListAddressesByRecord", model)); }
public static bool isTipstaffRecordChildAbduction(TipstaffRecord obj) { try { ChildAbduction CA = (ChildAbduction)obj; return(true); } catch { return(false); } }
public ActionResult Add(PoliceForceCreation model) { if (ModelState.IsValid) { TipstaffRecord tr = db.TipstaffRecord.Find(model.TS_PoliceForce.tipstaffRecordID); model.TS_PoliceForce.policeForceID = model.policeForceID; tr.policeForces.Add(model.TS_PoliceForce); db.SaveChanges(); return(RedirectToAction("Details", genericFunctions.TypeOfTipstaffRecord(tr), new { id = model.TS_PoliceForce.tipstaffRecordID, Area = "" })); } return(View(model)); }
public PartialViewResult ListSolicitorsByRecord(int id, int?page) { TipstaffRecord w = db.TipstaffRecord.Find(id); ListTipstaffRecordSolicitorByTipstaffRecord model = new ListTipstaffRecordSolicitorByTipstaffRecord(); model.tipstaffRecordID = w.tipstaffRecordID; model.LinkedSolicitors = w.LinkedSolicitors; model.TipstaffRecordClosed = w.caseStatusID > 2; model.pLinkedSolicitors = w.LinkedSolicitors.ToXPagedList <TipstaffRecordSolicitor>(page ?? 1, 8); //Note: Working Internal Paged list generation return(PartialView("_ListSolicitorsByRecord", model)); }
public PartialViewResult ListPNCIDAndNPOByRecord(int id) { TipstaffRecord w = db.TipstaffRecord.Find(id); ListPNCIDsNPO model = new ListPNCIDsNPO(); model.npo = new TipstaffNPO(); model.npo.tipstaffRecordID = w.tipstaffRecordID; model.npo.NPO = w.NPO; model.Respondents = w.Respondents.Where(r => r.PNCID != null).ToList(); if (genericFunctions.TypeOfTipstaffRecord(id) != "Warrant") { model.children = db.Children.Where(c => c.tipstaffRecordID == id && c.PNCID != null).ToList(); } return(PartialView("_ListPNCIDAndNPOByRecord", model)); }
public ActionResult Edit(RespondentCreationModel model) { if (ModelState.IsValid) { TipstaffRecord tr = db.TipstaffRecord.Find(model.tipstaffRecordID); if (tr is Warrant) { Warrant w = (Warrant)tr; w.RespondentName = model.respondent.PoliceDisplayName; db.Entry(w).State = EntityState.Modified; } db.Entry(model.respondent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", genericFunctions.TypeOfTipstaffRecord(model.respondent.tipstaffRecordID), new { id = model.respondent.tipstaffRecordID })); } return(View(model)); }
private string mergeDataA(Template template, TipstaffRecord tipstaffRecord, Applicant applicant) { string result = mergeData(template, tipstaffRecord); if (tipstaffRecord.NPO == null) { result = result.Replace("||NPOREFERENCE||", ""); } else { result = result.Replace("||NPOREFERENCE||", tipstaffRecord.NPO.Replace("&", "&")); } if (tipstaffRecord.addresses != null) { string addresses = ""; foreach (Address a in tipstaffRecord.addresses) { addresses += a.printAddressMultiLine + "<w:br/><w:br/>"; } if (addresses == "") { result = result.Replace("||POSSIBLEADDRESSES||", ""); } else { result = result.Replace("||POSSIBLEADDRESSES||", addresses); } } if (genericFunctions.TypeOfTipstaffRecord(tipstaffRecord) != "Warrant") //Check PNCIDs { string pncids = ""; ChildAbduction ca = (ChildAbduction)tipstaffRecord; foreach (Child c in ca.children) { if (c.PNCID != null && c.PNCID != "") { pncids += c.PNCID + "<w:br/>"; } } if (pncids == "") { result = result.Replace("||PNCIDS||", ""); } else { result = result.Replace("||PNCIDS||", pncids); } } if (applicant == null) { result = result.Replace("||ADDRESSEENAME||", ""); result = result.Replace("||ADDRESS||", "Add Address here"); } else { result = result.Replace("||ADDRESSEENAME||", applicant.fullname); if (applicant.printAddressMultiLine != null) { result = result.Replace("||ADDRESS||", applicant.printAddressMultiLine); } else { result = result.Replace("||ADDRESS||", ""); } } return(result); }
public ActionResult Create(RespondentCreationModel model, string submitButton) { if (!ModelState.IsValid) { return(View(model)); } try { TipstaffRecord tr = db.TipstaffRecord.Find(model.tipstaffRecordID); //if (genericFunctions.TypeOfTipstaffRecord(tr) == "Warrant") if (tr is Warrant) { Warrant w = (Warrant)tr; w.RespondentName = model.respondent.PoliceDisplayName; w.Respondents.Add(model.respondent); db.Entry(w).State = EntityState.Modified; db.SaveChanges(); } else { tr.Respondents.Add(model.respondent); } db.SaveChanges(); if (Request.IsAjaxRequest()) { string url = string.Format("window.location='{0}';", Url.Action("Details", genericFunctions.TypeOfTipstaffRecord(tr), new { id = model.tipstaffRecordID })); return(JavaScript(url)); } else { switch (submitButton) { case "Save,add new Respondent": return(RedirectToAction("Create", "Respondent", new { id = model.tipstaffRecordID, initial = model.initial })); case null: default: return(RedirectToAction("Details", genericFunctions.TypeOfTipstaffRecord(tr), new { id = model.tipstaffRecordID })); } } } catch (DbUpdateException ex) { _logger.LogError(ex, $"DbUpdateException in RespondentController in Create method, for user {((CPrincipal)User).UserID}"); if (Request.IsAjaxRequest()) { return(PartialView("_createRespondentForRecord", model)); } else { return(View(model)); } } catch (Exception ex) { _logger.LogError(ex, $"Exception in RespondentController in Create method, for user {((CPrincipal)User).UserID}"); ErrorModel errModel = new ErrorModel(2); errModel.ErrorMessage = genericFunctions.GetLowestError(ex); TempData["ErrorModel"] = errModel; return(RedirectToAction("IndexByModel", "Error", errModel ?? null)); } }
public static string TypeOfTipstaffRecord(TipstaffRecord obj) { return(isTipstaffRecordChildAbduction(obj) ? "ChildAbduction" : "Warrant"); }
public static List <SearchResultRow> getMatches(DateTime DoB) { TipstaffDB db = myDBContextHelper.CurrentContext; try { List <SearchResultRow> Results = new List <SearchResultRow>(); var kids = db.Children.Where(f => f.dateOfBirth == DoB); if (kids != null) { foreach (Child child in kids) { string uniqID = ""; using (TipstaffDB tempDB = new TipstaffDB()) { TipstaffRecord TR = tempDB.TipstaffRecord.Find(child.tipstaffRecordID); uniqID = TR.UniqueRecordID; }; Results.Add(new SearchResultRow { name = child.fullname, partyID = child.childID, tipstaffRecordID = child.tipstaffRecordID, DateOfBirth = (DateTime)child.dateOfBirth, PartyType = "Child", tipstaffRecordType = "ChildAbduction", tipstaffUniqueRecordID = uniqID }); } } var Resps = db.Respondents.Where(f => f.dateOfBirth == DoB); if (Resps != null) { foreach (Respondent resp in Resps) { string uniqID = ""; using (TipstaffDB tempDB = new TipstaffDB()) { TipstaffRecord TR = tempDB.TipstaffRecord.Find(resp.tipstaffRecordID); uniqID = TR.UniqueRecordID; }; Results.Add(new SearchResultRow { name = resp.fullname, partyID = resp.respondentID, tipstaffRecordID = resp.tipstaffRecordID, DateOfBirth = (DateTime)resp.dateOfBirth, PartyType = "Respondent", tipstaffRecordType = genericFunctions.TypeOfTipstaffRecord(resp.tipstaffRecordID), tipstaffUniqueRecordID = uniqID }); } } return(Results); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); return(null); } }
public static List <SearchResultRow> getMatches(string Name) { TipstaffDB db = myDBContextHelper.CurrentContext; string lowerName = Name.ToLower(); try { List <SearchResultRow> Results = new List <SearchResultRow>(); var kids = db.Children.Where(f => f.nameFirst.ToLower().Contains(lowerName) || f.nameMiddle.ToLower().Contains(lowerName) || f.nameLast.ToLower().Contains(lowerName)); if (kids != null) { foreach (Child child in kids) { string uniqID = ""; using (TipstaffDB tempDB = new TipstaffDB()) { TipstaffRecord TR = tempDB.TipstaffRecord.Find(child.tipstaffRecordID); uniqID = TR.UniqueRecordID; }; Results.Add(new SearchResultRow { name = child.fullname, partyID = child.childID, tipstaffRecordID = child.tipstaffRecordID, DateOfBirth = child.dateOfBirth, PartyType = "Child", tipstaffRecordType = "ChildAbduction", tipstaffUniqueRecordID = uniqID }); } } var Resps = db.Respondents.Where(f => f.nameFirst.ToLower().Contains(lowerName) || f.nameMiddle.ToLower().Contains(lowerName) || f.nameLast.ToLower().Contains(lowerName)); System.Diagnostics.Debug.Print(Resps.Count().ToString()); if (Resps != null) { foreach (Respondent resp in Resps) { string typePart2 = ""; string uniqID = ""; using (TipstaffDB tempDB = new TipstaffDB()) { if (genericFunctions.TypeOfTipstaffRecord(resp.tipstaffRecordID) == "Warrant") { Warrant temp = tempDB.Warrants.Find(resp.tipstaffRecordID); typePart2 = string.Format(" ({0})", temp.division.Detail); } TipstaffRecord TR = tempDB.TipstaffRecord.Find(resp.tipstaffRecordID); uniqID = TR.UniqueRecordID; }; Results.Add(new SearchResultRow { name = resp.fullname, partyID = resp.respondentID, tipstaffRecordID = resp.tipstaffRecordID, DateOfBirth = resp.dateOfBirth, PartyType = "Respondent", tipstaffRecordType = string.Format("{0}{1}", genericFunctions.TypeOfTipstaffRecord(resp.tipstaffRecordID) , typePart2), tipstaffUniqueRecordID = uniqID }); } } return(Results); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); //return null; throw new NotUploaded(ex.Message); } }
private string mergeData(Template template, TipstaffRecord tipstaffRecord) { string result = template.templateXML; int kids = 1; //merge generic fields result = result.Replace("||DATE||", DateTime.Now.ToShortDateString()); result = result.Replace("||TIME||", DateTime.Now.ToShortTimeString()); result = result.Replace("||NOW||", DateTime.Now.ToString("dd/MM/yy @ HH:mm")); result = result.Replace("||UNIQUERECORDID||", tipstaffRecord.UniqueRecordID); result = result.Replace("||USERNAME||", User.Identity.Name); if (tipstaffRecord.NPO == null) { result = result.Replace("||NPOREFERENCE||", ""); } else { result = result.Replace("||NPOREFERENCE||", tipstaffRecord.NPO.Replace("&", "&")); } if (tipstaffRecord.addresses != null) { string addresses = ""; foreach (Address a in tipstaffRecord.addresses) { addresses += a.printAddressMultiLine + "<w:br/><w:br/>"; } if (addresses == "") { result = result.Replace("||POSSIBLEADDRESSES||", ""); } else { result = result.Replace("||POSSIBLEADDRESSES||", addresses); } } else { result = result.Replace("||POSSIBLEADDRESSES||", ""); } if (tipstaffRecord.Respondents != null) { string respNames = ""; foreach (Respondent r in tipstaffRecord.Respondents) { respNames += r.PoliceDisplayName + " | "; } if (respNames == "") { result = result.Replace("||RESPONDENTSNAME||", "<<Please enter respondent's name"); } else { respNames = respNames.Substring(0, respNames.Length - 2); result = result.Replace("||RESPONDENTSNAME||", respNames); } } else { result = result.Replace("||RESPONDENTSNAME||", "<<Please enter respondent's name"); } foreach (Address addr in tipstaffRecord.addresses) { result = result.Replace("||ADDRESSES||", SecurityElement.Escape(addr.PrintAddressSingleLine) + "<w:br/>||ADDRESSES||"); result = result.Replace("||ADDRESSBLOCK||", addr.xmlBlock + "||ADDRESSBLOCK||"); } result = result.Replace("||ADDRESSES||", ""); result = result.Replace("||ADDRESSBLOCK||", ""); if (genericFunctions.TypeOfTipstaffRecord(tipstaffRecord) == "ChildAbduction" && template.Discriminator == "ChildAbduction") { ChildAbduction ca = (ChildAbduction)tipstaffRecord; PropertyInfo[] properties = typeof(ChildAbduction).GetProperties(); foreach (PropertyInfo property in properties) { var propValue = ""; object value = property.GetValue(ca, null); if (value != null) { Type type = value.GetType(); if (type == typeof(string) || type == typeof(int)) { propValue = value.ToString(); } else if (type == typeof(DateTime)) { propValue = ((DateTime)value).ToShortDateString(); } else if (type == typeof(object)) { //loop through properties of sub object System.Diagnostics.Debug.Print(propValue.ToString()); } } result = result.Replace(string.Format("||{0}||", property.Name.ToUpper()), SecurityElement.Escape(propValue)); } //child blocks foreach (Child child in ca.children) { result = result.Replace("||CHILDBLOCK||", child.xmlBlock.Replace("||CHILDNUMBER||", kids.ToString()) + "||CHILDBLOCK||"); kids++; } result = result.Replace("||MULTICHILD||", ca.children.Count() > 1 ? "children" : "child"); result = result.Replace("||CHILDBLOCK||", ""); result = result.Replace("||CHILDNUMBER||", ""); //respondent block foreach (Respondent resp in tipstaffRecord.Respondents) { result = result.Replace("||RESPONDENTBLOCK||", resp.xmlBlock + "||RESPONDENTBLOCK||"); } result = result.Replace("||RESPONDENTBLOCK||", ""); result = result.Replace("||MULTIRESP||", ca.Respondents.Count() > 1?"people":"person"); string pncids = ""; foreach (Respondent r in ca.Respondents) { if (r.PNCID != null && r.PNCID != "") { pncids += "(Respondent) " + r.PoliceDisplayName + " – " + r.PNCID + " – " + r.DateofBirthDisplay + " <w:br/>"; } } foreach (Child c in ca.children) { if (c.PNCID != null && c.PNCID != "") { pncids += "(Child) " + c.PoliceDisplayName + " – " + c.PNCID + " – " + c.DateofBirthDisplay + " <w:br/>"; } } if (pncids == "") { result = result.Replace("||PNCIDS||", ""); } else { result = result.Replace("||PNCIDS||", pncids); } } else if (template.Discriminator == "Warrant") { Warrant warrant = tipstaffRecord as Warrant; //result = result.Replace("||DIVISION||", warrant.division.Detail); PropertyInfo[] properties = typeof(Warrant).GetProperties(); foreach (PropertyInfo property in properties) { var propValue = ""; object value = property.GetValue(warrant, null); if (value != null) { Type type = value.GetType(); if (type == typeof(string) || type == typeof(int)) { propValue = value.ToString(); } else if (type == typeof(DateTime)) { propValue = ((DateTime)value).ToShortDateString(); } else if (type == typeof(object)) { //loop through properties of sub object System.Diagnostics.Debug.Print(propValue.ToString()); } } result = result.Replace(string.Format("||{0}||", property.Name.ToUpper()), SecurityElement.Escape(propValue)); } if (warrant.Respondents.Count() == 1) { PropertyInfo[] respProp = typeof(Respondent).GetProperties(); foreach (PropertyInfo property in respProp) { var propValue = ""; object value = property.GetValue(warrant.Respondents.FirstOrDefault(), null); if (value != null) { Type type = value.GetType(); if (type == typeof(string) || type == typeof(int)) { propValue = value.ToString(); } else if (type == typeof(DateTime)) { propValue = ((DateTime)value).ToShortDateString(); } else if (type == typeof(object)) { //loop through properties of sub object System.Diagnostics.Debug.Print(propValue.ToString()); } } result = result.Replace(string.Format("||{0}||", property.Name.ToUpper()), SecurityElement.Escape(propValue)); } result = result.Replace("||GENDER.DETAIL||", warrant.Respondents.FirstOrDefault().gender.detail); result = result.Replace("||NATIONALITY.DETAIL||", warrant.Respondents.FirstOrDefault().nationality.Detail); result = result.Replace("||COUNTRY.DETAIL||", warrant.Respondents.FirstOrDefault().country.Detail); result = result.Replace("||SKINCOLOUR.DETAIL||", warrant.Respondents.FirstOrDefault().SkinColour.Detail); string pncids = ""; if (warrant.Respondents.FirstOrDefault().PNCID != null && warrant.Respondents.FirstOrDefault().PNCID != "") { pncids += warrant.Respondents.FirstOrDefault().PNCID + "<w:br/>"; } if (pncids == "") { result = result.Replace("||PNCID||", ""); } else { result = result.Replace("||PNCID||", pncids); } } } return(result); }
// // GET: /Template/ public ActionResult Create(int tipstaffRecordID, int templateID) { try { //Get TipstaffRecord from warrantID TipstaffRecord tipstaffRecord = db.TipstaffRecord.Find(tipstaffRecordID); if (tipstaffRecord.caseStatus.sequence > 3) { TempData["UID"] = tipstaffRecord.UniqueRecordID; return(RedirectToAction("ClosedFile", "Error")); } //Get Template from templateID Template template = db.Templates.Find(templateID); if (template == null) { throw new FileLoadException(string.Format("No database record found for template reference {0}", templateID)); } //set fileOutput details WordFile fileOutput = new WordFile(tipstaffRecord, Server.MapPath("~/Documents/"), template); //Create XML object for Template XmlDocument xDoc = new XmlDocument(); //Merge Data xDoc.InnerXml = mergeData(template, tipstaffRecord, null); ////Save resulting document //xDoc.Save(fileOutput.fullName); //Save physical file //if (!System.IO.File.Exists(fileOutput.fullName)) throw new FileNotFoundException(string.Format("File {0} could not be created", fileOutput.fileName)); //Create and add a Document to TipstaffRecord Document doc = new Document(); doc.binaryFile = genericFunctions.ConvertToBytes(xDoc); doc.mimeType = "application/msword"; doc.fileName = fileOutput.fileName; doc.countryID = 244; //UK! doc.nationalityID = 27; doc.documentTypeID = 1; //generated doc.documentStatusID = 1; //generated doc.documentReference = template.templateName; doc.templateID = template.templateID; doc.createdOn = DateTime.Now; doc.createdBy = User.Identity.Name; tipstaffRecord.Documents.Add(doc); //Save Changes db.SaveChanges(); //Return saved document //return File(fileOutput.fullName, "application/doc", fileOutput.fileName); // return physical file return(File(doc.binaryFile, doc.mimeType, doc.fileName)); //return byte version } catch (DbEntityValidationException ex) { _logger.LogError(ex, $"DbEntityValidationException in TemplateController in Create method, for user {((CPrincipal)User).UserID}"); ErrorModel model = new ErrorModel(2); model.ErrorMessage = ex.Message; TempData["ErrorModel"] = model; return(RedirectToAction("IndexByModel", "Error", model ?? null)); } catch (Exception ex) { _logger.LogError(ex, $"Exception in TemplateController in Create method, for user {((CPrincipal)User).UserID}"); ErrorModel model = new ErrorModel(2); model.ErrorMessage = ex.Message; TempData["ErrorModel"] = model; return(RedirectToAction("IndexByModel", "Error", model ?? null)); //Note: working redirect to view with Model //Note: Working error redirect } }