Exemple #1
0
        // data modification methods

        public virtual void AddPersonResponsibility(PersonResponsibility pr)
        {
            if (this.PersonResponsibilities.Contains(pr))
            {
                return;
            }

            this.PersonResponsibilities.Add(pr);
        }
Exemple #2
0
        public IList <Event> GetEvents(Person p)
        {
            Event    suggestedEvent         = null;
            Location suggestedEventLocation = null;

            Event                e  = null;
            Location             l  = null;
            PersonResponsibility pr = null;

            Location             l1  = null;
            Event                e1  = null;
            PersonResponsibility pr1 = null;

            return(Session.QueryOver <Event>(() => suggestedEvent)
                   .JoinAlias(() => suggestedEvent.Location, () => suggestedEventLocation, JoinType.InnerJoin,
                              Restrictions.Where(() => !suggestedEventLocation.Archive))
                   .Where(Restrictions.Disjunction()
                          // either location of event for which person is responsible is identical
                          .Add(Subqueries.WhereExists(QueryOver.Of <PersonResponsibility>(() => pr)
                                                      .JoinAlias(() => pr.Event, () => e, JoinType.InnerJoin,
                                                                 Restrictions.Conjunction()
                                                                 .Add(Restrictions.Where(() => e.Id != suggestedEvent.Id))
                                                                 .Add(Restrictions.Where(() => !e.Archive))
                                                                 )
                                                      .JoinAlias(() => e.Location, () => l, JoinType.InnerJoin,
                                                                 Restrictions.Conjunction()
                                                                 .Add(Restrictions.Where(() => l.Id == suggestedEventLocation.Id))
                                                                 .Add(Restrictions.Where(() => !l.Archive))
                                                                 )
                                                      .Where(() => pr.Person == p)
                                                      .And(() => !pr.Archive)
                                                      .Select(x => x.Event)
                                                      ))
                          // or it's territory is
                          // TODO slow due to string = expression
                          .Add(Subqueries.WhereExists(QueryOver.Of <PersonResponsibility>(() => pr1)
                                                      .JoinAlias(() => pr1.Event, () => e1, JoinType.InnerJoin,
                                                                 Restrictions.Conjunction()
                                                                 .Add(Restrictions.Where(() => e1.Id != suggestedEvent.Id))
                                                                 .Add(Restrictions.Where(() => !e1.Archive))
                                                                 )
                                                      .JoinAlias(() => e1.Location, () => l1, JoinType.InnerJoin,
                                                                 Restrictions.Conjunction()
                                                                 .Add(Restrictions.Where(() => l1.Territory == suggestedEventLocation.Territory))
                                                                 .Add(Restrictions.On(() => l1.Territory).IsNotNull)
                                                                 .Add(Subqueries.WhereNotExists(QueryOver.Of <AdminUnknown>().Where(x => x.UnknownValue == l1.Territory).Select(x => x.Id)))
                                                                 .Add(Restrictions.Where(() => !l1.Archive))
                                                                 )
                                                      .Where(() => pr1.Person == p)
                                                      .And(() => !pr1.Archive)
                                                      .Select(x => x.Event)
                                                      ))
                          )
                   .And(() => !suggestedEvent.Archive)
                   .List());
        }
 public void DeletePersonResponsibility(PersonResponsibility pr)
 {
     pr.Event.RemovePersonResponsibility(pr);
     foreach (Violation v in pr.Violations)
     {
         v.RemovePersonResponsibility(pr);
     }
     pr.Person.RemovePersonResponsibility(pr);
     this.personResponsibilityRepo.Delete(pr);
 }
Exemple #4
0
        public virtual bool AddPersonResponsibility(PersonResponsibility pr)
        {
            if (this.PersonResponsibilities.Contains(pr))
            {
                return(false);
            }

            this.PersonResponsibilities.Add(pr);
            pr.Person.AddPersonResponsibility(pr);
            return(true);
        }
Exemple #5
0
 public JsonNetResult Add(PersonResponsibilityViewModel vm)
 {
     if (ModelState.IsValid)
     {
         Event  e = this.eventTasks.GetEvent(vm.EventId.Value);
         Person p = this.personTasks.GetPerson(vm.PersonId.Value);
         if (e != null && p != null)
         {
             PersonResponsibility pr = new PersonResponsibility();
             pr.Event = e;
             if (!string.IsNullOrEmpty(vm.ViolationIds))
             {
                 string[] ids = vm.ViolationIds.Split(',');
                 foreach (string id in ids)
                 {
                     int result;
                     if (int.TryParse(id, out result))
                     {
                         Violation v = this.eventTasks.GetViolation(result);
                         if (v != null)
                         {
                             pr.AddViolation(v);
                         }
                     }
                 }
             }
             pr.Person = p;
             pr.PersonResponsibilityType = this.responsibilityTasks.GetPersonResponsibilityType(vm.PersonResponsibilityTypeId.Value);
             pr.Commentary = vm.Commentary;
             pr.Notes      = vm.Notes;
             pr.Archive    = false;
             if (e.AddPersonResponsibility(pr))
             {
                 e = this.eventTasks.SaveEvent(e);
                 return(JsonNet(string.Empty));
             }
             else
             {
                 Response.StatusCode = (int)HttpStatusCode.BadRequest;
                 return(JsonNet("Person responsibility already exists for this event."));
             }
         }
         else
         {
             Response.StatusCode = (int)HttpStatusCode.NotFound;
             return(JsonNet("Event or person does not exist."));
         }
     }
     else
     {
         return(JsonNet(this.GetErrorsForJson()));
     }
 }
Exemple #6
0
        public ActionResult Edit(int id)
        {
            PersonResponsibility pr = this.responsibilityTasks.GetPersonResponsibility(id);

            if (pr != null)
            {
                PersonResponsibilityViewModel vm = new PersonResponsibilityViewModel(pr, pr.Event.EventSources.Select(x => this.sourceTasks.GetSourceDTO(x.Source.Id)).ToList());
                vm.PopulateDropDowns(this.responsibilityTasks.GetPersonResponsibilityTypes());
                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
Exemple #7
0
 public ActionResult List(IEnumerable <int> ids)
 {
     if (ids != null && ids.Any())
     {
         foreach (int id in ids)
         {
             PersonResponsibility pr = this.responsibilityTasks.GetPersonResponsibility(id);
             pr.Commentary = string.Empty;
             this.responsibilityTasks.SavePersonResponsibility(pr);
         }
     }
     return(null);
 }
Exemple #8
0
        public JsonNetResult Delete(int id)
        {
            PersonResponsibility pr = responsibilityTasks.GetPersonResponsibility(id);

            if (pr != null)
            {
                this.responsibilityTasks.DeletePersonResponsibility(pr);
                Response.StatusCode = (int)HttpStatusCode.OK;
                return(JsonNet("Person's responsibility for event successfully removed."));
            }
            Response.StatusCode = (int)HttpStatusCode.NotFound;
            return(JsonNet("Responsibility not found."));
        }
Exemple #9
0
 /// <summary>
 /// Instantiate ViewModel using given DTOs.
 /// </summary>
 /// <param name="pr"></param>
 /// <param name="sources">This must include all SourceDTOs attached to the PersonResponsibility's event.</param>
 public PersonResponsibilityViewModel(PersonResponsibility pr, IList <SourceDTO> sources)
 {
     this.CreateLists();
     this.Id           = pr.Id;
     this.ViolationIds = string.Join(",", pr.Violations.Select(x => x.Id.ToString()));
     this.Violations   = pr.Violations.Select(x => new { Id = x.Id, Name = x.Name }).ToList <object>();
     this.PersonResponsibilityTypeId = pr.PersonResponsibilityType.Id;
     this.Commentary = pr.Commentary;
     this.Archive    = pr.Archive;
     this.Notes      = pr.Notes;
     this.PersonResponsibilityTypeName = pr.PersonResponsibilityType.ToString();
     this.PersonFunctionUnitSummary    = pr.GetPersonFunctionUnitSummary();
     this.SetPerson(pr.Person);
     this.SetEvent(pr.Event, sources);
 }
        public PersonResponsibility SavePersonResponsibility(PersonResponsibility pr)
        {
            pr.Event.AddPersonResponsibility(pr);
            foreach (Violation v in pr.Violations)
            {
                v.AddPersonResponsibility(pr);
            }
            pr.Person.AddPersonResponsibility(pr);

            if (!pr.Person.HasValidProfileStatus())
            {
                pr.Person.ProfileStatus = this.personTasks.GetProfileStatus(ProfileStatus.ROUGH_OUTLINE);
                this.personTasks.SavePerson(pr.Person);
            }

            return(this.personResponsibilityRepo.SaveOrUpdate(pr));
        }
Exemple #11
0
 public JsonNetResult Edit(PersonResponsibilityViewModel vm)
 {
     if (ModelState.IsValid)
     {
         PersonResponsibility pr = this.responsibilityTasks.GetPersonResponsibility(vm.Id);
         if (pr != null)
         {
             pr.Violations.Clear();
             if (!string.IsNullOrEmpty(vm.ViolationIds))
             {
                 string[] ids = vm.ViolationIds.Split(',');
                 foreach (string id in ids)
                 {
                     int result;
                     if (int.TryParse(id, out result))
                     {
                         Violation v = this.eventTasks.GetViolation(result);
                         if (v != null)
                         {
                             pr.AddViolation(v);
                         }
                     }
                 }
             }
             pr.PersonResponsibilityType = this.responsibilityTasks.GetPersonResponsibilityType(vm.PersonResponsibilityTypeId.Value);
             pr.Commentary = vm.Commentary;
             pr.Notes      = vm.Notes;
             pr            = this.responsibilityTasks.SavePersonResponsibility(pr);
             return(JsonNet(string.Empty));
         }
         Response.StatusCode = (int)HttpStatusCode.NotFound;
         return(JsonNet("Responsibility not found."));
     }
     else
     {
         return(JsonNet(this.GetErrorsForJson()));
     }
 }
Exemple #12
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)));
        }
Exemple #13
0
 public virtual void RemovePersonResponsibility(PersonResponsibility pr)
 {
     this.PersonResponsibilities.Remove(pr);
 }