Exemplo n.º 1
0
        public ActionResult Event(int sourceId, int targetId)
        {
            Source source = this.sourceTasks.GetSource(sourceId);

            if (source != null)
            {
                Profiling2.Domain.Prf.Events.Event ev = this.eventTasks.GetEvent(targetId);
                if (ev != null)
                {
                    EventSourceViewModel vm = new EventSourceViewModel();
                    vm.SourceId = source.Id;
                    vm.EventId  = ev.Id;
                    vm.PopulateDropDowns(this.sourceTasks.GetReliabilities());

                    ViewBag.Event  = ev;
                    ViewBag.Source = source;

                    EventSource es = source.GetEventSource(ev);
                    if (es != null)
                    {
                        // Event is already attached to Source
                        vm.Id         = es.Id;
                        vm.Commentary = es.Commentary;
                        vm.Notes      = es.Notes;
                    }

                    return(View(vm));
                }
            }
            return(new HttpNotFoundResult());
        }
Exemplo n.º 2
0
 // TODO this detaches the event if POSTed an EventSource.Id.  Function replicated in EventSourcesController.
 public JsonNetResult Event(EventSourceViewModel vm)
 {
     if (vm.Id.HasValue)
     {
         this.sourceAttachmentTasks.DeleteEventSource(vm.Id.Value);
         Response.StatusCode = (int)HttpStatusCode.OK;
         return(JsonNet("Event successfully detached from source."));
     }
     else if (ModelState.IsValid)
     {
         Source source = this.sourceTasks.GetSource(vm.SourceId.Value);
         Profiling2.Domain.Prf.Events.Event ev = this.eventTasks.GetEvent(vm.EventId.Value);
         if (source != null && ev != null)
         {
             if (source.GetEventSource(ev) == null)
             {
                 EventSource es = new EventSource();
                 es.Source      = source;
                 es.Event       = ev;
                 es.Reliability = this.sourceTasks.GetReliability(vm.ReliabilityId.Value);
                 es.Commentary  = vm.Commentary;
                 es.Notes       = vm.Notes;
                 this.sourceAttachmentTasks.SaveEventSource(es);
             }
             Response.StatusCode = (int)HttpStatusCode.OK;
             return(JsonNet("Event successfully attached."));
         }
         else
         {
             Response.StatusCode = (int)HttpStatusCode.NotFound;
             return(JsonNet("Event or source not found."));
         }
     }
     else
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(JsonNet("Form failed validation."));
     }
 }