Ejemplo n.º 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()));
     }
 }
Ejemplo n.º 2
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()));
     }
 }