Example #1
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()));
     }
 }
Example #2
0
        public ActionResult Add(int eventId)
        {
            Event e = this.eventTasks.GetEvent(eventId);

            if (e != null)
            {
                PersonResponsibilityViewModel vm = new PersonResponsibilityViewModel(e, e.EventSources.Select(x => this.sourceTasks.GetSourceDTO(x.Source.Id)).ToList());
                vm.PopulateDropDowns(this.responsibilityTasks.GetPersonResponsibilityTypes());
                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
Example #3
0
        public ActionResult AddForPerson(int personId)
        {
            Person p = this.personTasks.GetPerson(personId);

            if (p != null)
            {
                PersonResponsibilityViewModel vm = new PersonResponsibilityViewModel(p);
                vm.PopulateDropDowns(this.responsibilityTasks.GetPersonResponsibilityTypes());
                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
Example #4
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());
        }
Example #5
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()));
     }
 }
Example #6
0
 public JsonNetResult AddForPerson(PersonResponsibilityViewModel vm)
 {
     return(Add(vm));
 }