Example #1
0
 public JsonNetResult Add(PersonResponsibilityTypeViewModel vm)
 {
     if (ModelState.IsValid)
     {
         // TODO unique constraint on name
         PersonResponsibilityType type = new PersonResponsibilityType();
         type.PersonResponsibilityTypeName = vm.PersonRelationshipTypeName;
         type.Notes = vm.Notes;
         type       = this.responsibilityTasks.SavePersonResponsibilityType(type);
         return(JsonNet(string.Empty));
     }
     else
     {
         return(JsonNet(this.GetErrorsForJson()));
     }
 }
Example #2
0
        public ActionResult Import(HrdbCaseViewModel vm)
        {
            JhroCase jc = this.sourceTasks.GetJhroCase(vm.Id);

            // if an existing Event is selected, ignore validation errors to do with new event
            if (vm.EventId.HasValue)
            {
                // TODO brittle
                ModelState.Remove("Event.ViolationIds");
                ModelState.Remove("Event.LocationId");
            }

            if (ModelState.IsValid)
            {
                Event e = null;
                if (vm.EventId.HasValue)
                {
                    e = this.eventTasks.GetEvent(vm.EventId.Value);
                    e.AddJhroCase(jc);
                }
                else
                {
                    // create new event - TODO duplicates code in other EventsController
                    e = new Event();
                    Mapper.Map <EventViewModel, Event>(vm.Event, e);
                    if (!string.IsNullOrEmpty(vm.Event.ViolationIds))
                    {
                        string[] ids = vm.Event.ViolationIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                Violation v = this.eventTasks.GetViolation(result);
                                if (v != null)
                                {
                                    e.Violations.Add(v);
                                }
                            }
                        }
                    }
                    e.Location            = this.locationTasks.GetLocation(vm.Event.LocationId.Value);
                    e.EventVerifiedStatus = vm.Event.EventVerifiedStatusId.HasValue ? this.eventTasks.GetEventVerifiedStatus(vm.Event.EventVerifiedStatusId.Value) : null;
                    if (!string.IsNullOrEmpty(vm.Event.TagIds))
                    {
                        string[] ids = vm.Event.TagIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                Tag t = this.eventTasks.GetTag(result);
                                if (t != null)
                                {
                                    e.Tags.Add(t);
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(vm.Event.JhroCaseIds))
                    {
                        string[] ids = vm.Event.JhroCaseIds.Split(',');
                        foreach (string id in ids)
                        {
                            int result;
                            if (int.TryParse(id, out result))
                            {
                                JhroCase jhroCase = this.sourceTasks.GetJhroCase(result);
                                if (jhroCase != null)
                                {
                                    e.AddJhroCase(jhroCase);
                                }
                            }
                        }
                    }
                }

                // create responsibilities
                if (e != null && vm.HrdbPerpetrators != null)
                {
                    foreach (HrdbPerpetratorViewModel pvm in vm.HrdbPerpetrators)
                    {
                        if (pvm.PersonId.HasValue)
                        {
                            Person p = this.personTasks.GetPerson(pvm.PersonId.Value);
                            if (p != null)
                            {
                                if (pvm.PersonResponsibilityTypeId.HasValue)
                                {
                                    PersonResponsibilityType prt = this.responsibilityTasks.GetPersonResponsibilityType(pvm.PersonResponsibilityTypeId.Value);
                                    if (prt != null)
                                    {
                                        PersonResponsibility pr = new PersonResponsibility()
                                        {
                                            Event  = e,
                                            Person = p,
                                            PersonResponsibilityType = prt,
                                            Violations = pvm.GetViolationIds().Select(x => this.eventTasks.GetViolation(x)).ToList()
                                        };

                                        e.AddPersonResponsibility(pr);
                                    }
                                }
                            }
                        }
                        else if (pvm.OrganizationId.HasValue)
                        {
                            Organization o = this.orgTasks.GetOrganization(pvm.OrganizationId.Value);
                            if (o != null)
                            {
                                if (pvm.OrganizationResponsibilityTypeId.HasValue)
                                {
                                    OrganizationResponsibilityType ort = this.responsibilityTasks.GetOrgResponsibilityType(pvm.OrganizationResponsibilityTypeId.Value);
                                    if (ort != null)
                                    {
                                        OrganizationResponsibility or = new OrganizationResponsibility()
                                        {
                                            Event        = e,
                                            Organization = o,
                                            OrganizationResponsibilityType = ort
                                        };

                                        e.AddOrganizationResponsibility(or);
                                    }
                                }
                            }
                        }
                    }
                }

                e = this.eventTasks.SaveEvent(e);

                return(RedirectToAction("Details", "Cases", new { id = jc.Id }));
            }

            return(Import(new JhroCaseViewModel(jc)));
        }
Example #3
0
 public PersonResponsibilityType SavePersonResponsibilityType(PersonResponsibilityType type)
 {
     return(this.personResponsibilityTypeRepo.SaveOrUpdate(type));
 }