Ejemplo n.º 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));
     }
 }
Ejemplo n.º 2
0
 public ActionResult Add(TipstaffNPO model)
 {
     if (ModelState.IsValid)
     {
         string controller = genericFunctions.TypeOfTipstaffRecord(model.tipstaffRecordID);
         if (controller == "Warrant")
         {
             Warrant w = db.Warrants.Find(model.tipstaffRecordID);
             w.NPO             = model.NPO;
             db.Entry(w).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Details", "Warrant", new { id = w.tipstaffRecordID }));
         }
         else
         {
             ChildAbduction ca = db.ChildAbductions.Find(model.tipstaffRecordID);
             ca.NPO             = model.NPO;
             db.Entry(ca).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Details", "ChildAbduction", new { id = ca.tipstaffRecordID }));
         }
     }
     else
     {
         return(View(model));
     }
 }
 public static bool isTipstaffRecordChildAbduction(TipstaffRecord obj)
 {
     try
     {
         ChildAbduction CA = (ChildAbduction)obj;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
 public ActionResult Edit(ChildAbduction childabduction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(childabduction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", "ChildAbduction", new { id = childabduction.tipstaffRecordID }));
     }
     ViewBag.protectiveMarkingID = new SelectList(db.ProtectiveMarkings.Where(x => x.active == true), "protectiveMarkingID", "Detail", childabduction.protectiveMarkingID);
     ViewBag.caseStatusID        = new SelectList(db.CaseStatuses.Where(x => x.active == true), "caseStatusID", "Detail", childabduction.caseStatusID);
     ViewBag.caOrderTypeID       = new SelectList(db.CAOrderTypes.Where(x => x.active == true), "caOrderTypeID", "Detail", childabduction.caOrderTypeID);
     return(View(childabduction));
 }
Ejemplo n.º 5
0
        //
        // GET: /ChildAbduction/Create

        public ActionResult Create()
        {
            ViewBag.protectiveMarkingList        = new SelectList(db.ProtectiveMarkings.Where(x => x.active == true).ToList(), "protectiveMarkingID", "Detail");
            ViewBag.childAbductionCaseStatusList = new SelectList(db.CaseStatuses.Where(x => x.active == true).OrderBy(x => x.sequence), "caseStatusID", "Detail");
            ViewBag.caOrderTypeID = new SelectList(db.CAOrderTypes.Where(x => x.active == true), "caOrderTypeID", "Detail");
            ChildAbduction model = new ChildAbduction();

            model.nextReviewDate = DateTime.Today.AddMonths(1);
            System.Security.Principal.IIdentity userIdentity = User.Identity;
            Tipstaff.CPrincipal thisUser = new CPrincipal(userIdentity);
            model.createdBy = thisUser.User.DisplayName;
            return(View(model));
        }
Ejemplo n.º 6
0
        //
        // GET: /ChildAbduction/Edit/5

        public ActionResult Edit(int id)
        {
            ChildAbduction childabduction = db.ChildAbductions.Find(id);

            if (childabduction.caseStatus.sequence > 3)  //.caseStatus.sequence > 3)
            {
                TempData["UID"] = childabduction.UniqueRecordID;
                return(RedirectToAction("ClosedFile", "Error"));
            }
            ViewBag.protectiveMarkingID = new SelectList(db.ProtectiveMarkings.Where(x => x.active == true), "protectiveMarkingID", "Detail", childabduction.protectiveMarkingID);
            ViewBag.caseStatusID        = new SelectList(db.CaseStatuses.Where(x => x.active == true), "caseStatusID", "Detail", childabduction.caseStatusID);
            ViewBag.caOrderTypeID       = new SelectList(db.CAOrderTypes.Where(x => x.active == true), "caOrderTypeID", "Detail", childabduction.caOrderTypeID);
            return(View(childabduction));
        }
Ejemplo n.º 7
0
        public ActionResult Create(ChildAbduction childabduction)
        {
            if (ModelState.IsValid)
            {
                db.TipstaffRecord.Add(childabduction);
                db.SaveChanges();
                return(RedirectToAction("Create", "Child", new { id = childabduction.tipstaffRecordID, initial = true }));
            }

            ViewBag.protectiveMarkingID = new SelectList(db.ProtectiveMarkings.Where(x => x.active == true), "protectiveMarkingID", "Detail", childabduction.protectiveMarkingID);
            ViewBag.caseStatusID        = new SelectList(db.CaseStatuses.Where(x => x.active == true), "caseStatusID", "Detail", childabduction.caseStatusID);
            ViewBag.caOrderTypeID       = new SelectList(db.CAOrderTypes.Where(x => x.active == true), "caOrderTypeID", "Detail", childabduction.caOrderTypeID);
            return(View(childabduction));
        }
        public PartialViewResult ListRespondentsByRecord(int id, int?page)
        {
            ListRespondentsByTipstaffRecord model = new ListRespondentsByTipstaffRecord();

            try
            {
                ChildAbduction ca = db.ChildAbductions.Find(id);
                model.tipstaffRecordID = ca.tipstaffRecordID;
                model.Respondents      = ca.Respondents.ToXPagedList <Respondent>(page ?? 1, 8);
            }
            catch
            {
                //do nothing!  Return empty model
            }
            return(PartialView("_ListRespondentsByRecord", model));
        }
Ejemplo n.º 9
0
        private void GetRows <T>(List <T> dataToAdd)
        {
            foreach (var item in dataToAdd)
            {
                if (item.GetType().BaseType == typeof(ChildAbduction))
                {
                    ChildAbduction CA = item as ChildAbduction;

                    var dataRow = new XElement(mainNamespace + "Row",
                                               new XElement(mainNamespace + "Cell",
                                                            new XElement(mainNamespace + "Data", new XAttribute(ss + "Type", "String"), CA.UniqueRecordID))
                                               );
                    rows.Add(dataRow);
                }
            }
        }
Ejemplo n.º 10
0
        public PartialViewResult ListApplicantsByRecord(int id, int?page)
        {
            ListApplicantsByTipstaffRecord model = new ListApplicantsByTipstaffRecord();

            try
            {
                ChildAbduction ca = db.ChildAbductions.Find(id);
                model.tipstaffRecordID     = ca.tipstaffRecordID;
                model.Applicants           = ca.Applicants.ToXPagedList <Applicant>(page ?? 1, 8);
                model.TipstaffRecordClosed = ca.caseStatus.sequence > 3;
            }
            catch
            {
                //do nothing!  Return empty model
            }
            return(PartialView("_ListApplicantsByRecord", model));
        }
        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("&", "&#038;"));
            }
            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 + " &#8211; " + r.PNCID + " &#8211; " + r.DateofBirthDisplay + " <w:br/>";
                    }
                }
                foreach (Child c in ca.children)
                {
                    if (c.PNCID != null && c.PNCID != "")
                    {
                        pncids += "(Child) " + c.PoliceDisplayName + " &#8211; " + c.PNCID + " &#8211; " + 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);
        }
        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("&", "&#038;"));
            }
            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);
        }
Ejemplo n.º 13
0
        //
        // GET: /ChildAbduction/Details/5

        public ViewResult Details(int id)
        {
            ChildAbduction childabduction = db.ChildAbductions.Find(id);

            return(View(childabduction));
        }
        public ActionResult Create(ChildCreationModel model, string submitButton)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                ChildAbduction ca = db.ChildAbductions.Find(model.tipstaffRecordID);

                /* if
                 *  EldestChild is null or
                 *  new child is eldest
                 * Add the surname of this child to the CA record
                 */
                Child  curEldest  = ca.children.OrderBy(c => c.dateOfBirth).ThenBy(c => c.childID).FirstOrDefault();
                string newSurname = model.child.nameLast; //by default set to new childs name
                if (curEldest != null)
                {
                    if (model.child.dateOfBirth > curEldest.dateOfBirth)
                    {
                        newSurname = curEldest.nameLast;
                    }
                }
                ca.EldestChild = newSurname.ToUpper();
                //Add new child
                ca.children.Add(model.child);

                //Now save the changes
                db.SaveChanges();

                if (Request.IsAjaxRequest())
                {
                    string url = string.Format("window.location='{0}';", Url.Action("Details", "ChildAbduction", new { id = model.tipstaffRecordID }));
                    return(JavaScript(url));
                }
                else
                {
                    switch (submitButton)
                    {
                    case "Save and add new Child":
                        return(RedirectToAction("Create", "Child", new { id = model.tipstaffRecordID, initial = model.initial }));

                    case "Save,add new Respondent":
                        return(RedirectToAction("Create", "Respondent", new { id = model.tipstaffRecordID, initial = model.initial }));

                    case null:
                    default:
                        return(RedirectToAction("Details", "ChildAbduction", new { id = model.tipstaffRecordID }));
                    }
                }
            }
            catch (DbUpdateException)
            {
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_createChildRecordForRecord", model));
                }
                else
                {
                    return(View(model));
                }
            }
            catch (ValidationException ex)
            {
                ErrorModel errModel = new ErrorModel(2);
                errModel.ErrorMessage  = genericFunctions.GetLowestError(ex);
                TempData["ErrorModel"] = errModel;
                return(RedirectToAction("IndexByModel", "Error", errModel ?? null));
            }
            catch (DbEntityValidationException ex)
            {
                ErrorModel errModel = new ErrorModel(2);
                errModel.ErrorMessage  = genericFunctions.GetLowestError(ex);
                TempData["ErrorModel"] = errModel;
                return(RedirectToAction("IndexByModel", "Error", errModel ?? null));
            }
            catch (Exception ex)
            {
                ErrorModel errModel = new ErrorModel(2);
                errModel.ErrorMessage  = genericFunctions.GetLowestError(ex);
                TempData["ErrorModel"] = errModel;
                return(RedirectToAction("IndexByModel", "Error", errModel ?? null));
            }
        }