Example #1
0
 public ActionResult Create(ApplicantCreationModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         ChildAbduction ca = db.ChildAbductions.Find(model.tipstaffRecordID);
         ca.Applicants.Add(model.applicant);
         db.SaveChanges();
         if (Request.IsAjaxRequest())
         {
             string url = string.Format("window.location='{0}';", Url.Action("Details", "ChildAbduction", new { id = model.tipstaffRecordID }));
             return(JavaScript(url));
         }
         else
         {
             return(RedirectToAction("Details", "ChildAbduction", new { id = model.tipstaffRecordID }));
         }
     }
     catch (DbUpdateException ex)
     {
         _logger.LogError(ex, $"DbUpdateException in ApplicantController in Create method, for user {((CPrincipal)User).UserID}");
         return(View(model));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"Exception in ApplicantController 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));
     }
 }
Example #2
0
        // POST: /TipstaffRecordSolicitor/Create

        public ActionResult Create(int tipstaffRecord, int solicitor)
        {
            TipstaffRecordSolicitor tipstaffrecordsolicitor = new TipstaffRecordSolicitor();

            tipstaffrecordsolicitor.solicitor      = db.Solicitors.Find(solicitor);
            tipstaffrecordsolicitor.tipstaffRecord = db.TipstaffRecord.Find(tipstaffRecord);
            if (tipstaffrecordsolicitor.tipstaffRecord.caseStatus.sequence > 3)
            {
                TempData["UID"] = tipstaffrecordsolicitor.tipstaffRecord.UniqueRecordID;
                return(RedirectToAction("ClosedFile", "Error"));
            }

            try
            {
                //throw new DbUpdateException(");
                db.TipstaffRecordSolicitors.Add(tipstaffrecordsolicitor);
                db.SaveChanges();
                if (Request.IsAjaxRequest())
                {
                    string url = string.Format("window.location='{0}';", Url.Action("Details", genericFunctions.TypeOfTipstaffRecord(tipstaffrecordsolicitor.tipstaffRecord), new { id = tipstaffRecord }));
                    //return JavaScript("location.reload(true)");
                    return(JavaScript(url));
                }
                else
                {
                    return(RedirectToAction("Details", genericFunctions.TypeOfTipstaffRecord(tipstaffrecordsolicitor.tipstaffRecord), new { id = tipstaffRecord }));
                }
            }
            catch (DbUpdateException ex)
            {
                _logger.LogError(ex, $"DbUpdateException in TipstaffRecordSolicitorController in Create method, for user {((CPrincipal)User).UserID}");

                TipstaffRecordSolicitorErrorViewModel model = new TipstaffRecordSolicitorErrorViewModel();
                model.tipstaffrecordsolicitor = tipstaffrecordsolicitor;

                if (ex.InnerException.InnerException.Message.StartsWith("Violation of PRIMARY"))
                {
                    model.ErrorMessage = "The chosen solicitor is already linked to this record";
                }
                else
                {
                    model.ErrorMessage = ex.InnerException.InnerException.Message;
                }
                TempData["TRSError"] = model;
                return(RedirectToAction("Error", "TipstaffRecordSolicitor"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Exception in TipstaffRecordSolicitorController in Create method, for user {((CPrincipal)User).UserID}");

                ErrorModel model = new ErrorModel();
                model.ErrorMessage = ex.Message;
                return(View("Error", model));
            }
        }
Example #3
0
        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));
            }
        }
Example #4
0
 public ActionResult EnterResult(TipstaffRecordResolutionModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             model.tipstaffRecord = db.TipstaffRecord.Find(model.tipstaffRecordID);
             model.tipstaffRecord.nextReviewDate  = DateTime.Today.AddDays(1);
             model.tipstaffRecord.resultDate      = DateTime.Now;
             model.tipstaffRecord.DateExecuted    = model.DateExecuted;
             model.tipstaffRecord.resultID        = model.resultID;
             model.tipstaffRecord.resultEnteredBy = User.Identity.Name;
             model.tipstaffRecord.prisonCount     = model.pCount;
             model.tipstaffRecord.arrestCount     = model.aCount;
             model.tipstaffRecord.caseStatusID    = 3;
             db.Entry(model.tipstaffRecord).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Details", "ChildAbduction", new { id = model.tipstaffRecordID }));
         }
         catch (Exception ex)
         {
             _logger.LogError(ex, $"Exception in ChildAbductionController in EnterResult 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));
         }
     }
     return(View(model));
 }
Example #5
0
        protected void Application_Error(object sender, EventArgs e)
        {
            //Handle nonce exception
            var ex = Server.GetLastError();

            _cloudWatchLogger.LogError(ex, "Application_Error");

            if ((ex.GetType() == typeof(OpenIdConnectProtocolInvalidNonceException) && User.Identity.IsAuthenticated) && (ex.Message.StartsWith("OICE_20004") || ex.Message.Contains("IDX10311")))
            {
                Server.ClearError();
                Response.Redirect(Request.RawUrl);
            }
        }
Example #6
0
        public ActionResult ExtractDocument(int id)
        {
            try
            {
                Document doc = db.Documents.Find(id);
                if (doc == null)
                {
                    ErrorModel errModel = new ErrorModel(2);
                    errModel.ErrorMessage  = string.Format("Document {0} has been deleted, please raise a help desk call if you think this has been deleted in error.", id);
                    TempData["ErrorModel"] = errModel;
                    return(RedirectToAction("IndexByModel", "Error", new { area = "", model = errModel ?? null }));
                }
                byte[] file = doc.binaryFile;
                return(File(file, doc.mimeType, doc.fileName));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Exception in DocumentController in ExtractDocument method, for user {((CPrincipal)User).UserID}");

                return(View("Error"));
            }
        }
        //
        // 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
            }
        }
        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));
            }
        }