public ActionResult Edit(int id)
        {
            OrganizationResponsibility or = responsibilityTasks.GetOrganizationResponsibility(id);

            if (or != null)
            {
                OrgResponsibilityViewModel vm = new OrgResponsibilityViewModel(or);
                vm.PopulateDropDowns(this.responsibilityTasks.GetOrgResponsibilityTypes());
                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
        public ActionResult Add(int eventId)
        {
            Event e = this.eventTasks.GetEvent(eventId);

            if (e != null)
            {
                OrgResponsibilityViewModel vm = new OrgResponsibilityViewModel(e);
                vm.PopulateDropDowns(this.responsibilityTasks.GetOrgResponsibilityTypes());
                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
Example #3
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value != null)
            {
                OrgResponsibilityViewModel vm = (OrgResponsibilityViewModel)value;  // could generalize this by adding an interface to the view model

                // don't allow a responsibility where the unit is not a part of the organization
                if (vm.OrganizationId.HasValue && vm.UnitId.HasValue)
                {
                    Organization o = ServiceLocator.Current.GetInstance <IOrganizationTasks>().GetOrganization(vm.OrganizationId.Value);
                    Unit         u = ServiceLocator.Current.GetInstance <IOrganizationTasks>().GetUnit(vm.UnitId.Value);
                    if (!u.IsPartOf(o))
                    {
                        return(new ValidationResult(this.ErrorMessage));
                    }
                }
            }
            return(ValidationResult.Success);
        }
 public JsonNetResult Add(OrgResponsibilityViewModel vm)
 {
     if (ModelState.IsValid)
     {
         Event        e = this.eventTasks.GetEvent(vm.EventId);
         Organization o = this.organizationTasks.GetOrganization(vm.OrganizationId.Value);
         if (e != null && o != null)
         {
             OrganizationResponsibility or = new OrganizationResponsibility();
             or.Event        = e;
             or.Organization = o;
             or.Unit         = vm.UnitId.HasValue ? this.organizationTasks.GetUnit(vm.UnitId.Value) : null;
             or.OrganizationResponsibilityType = this.responsibilityTasks.GetOrgResponsibilityType(vm.OrganizationResponsibilityTypeId);
             or.Commentary = vm.Commentary;
             or.Notes      = vm.Notes;
             or.Archive    = false;
             if (e.AddOrganizationResponsibility(or))
             {
                 e = this.eventTasks.SaveEvent(e);
                 return(JsonNet(string.Empty));
             }
             else
             {
                 Response.StatusCode = (int)HttpStatusCode.BadRequest;
                 return(JsonNet("Organization/unit responsibility already exists."));
             }
         }
         else
         {
             Response.StatusCode = (int)HttpStatusCode.NotFound;
             return(JsonNet("Event or organization does not exist."));
         }
     }
     else
     {
         return(JsonNet(this.GetErrorsForJson()));
     }
 }
 public JsonNetResult Edit(OrgResponsibilityViewModel vm)
 {
     if (ModelState.IsValid)
     {
         OrganizationResponsibility or = responsibilityTasks.GetOrganizationResponsibility(vm.Id);
         if (or != null)
         {
             // assuming event, org are the same
             or.Unit = vm.UnitId.HasValue ? this.organizationTasks.GetUnit(vm.UnitId.Value) : null;
             or.OrganizationResponsibilityType = this.responsibilityTasks.GetOrgResponsibilityType(vm.OrganizationResponsibilityTypeId);
             or.Commentary = vm.Commentary;
             or.Notes      = vm.Notes;
             or            = this.responsibilityTasks.SaveOrganizationResponsibility(or);
             return(JsonNet(string.Empty));
         }
         Response.StatusCode = (int)HttpStatusCode.NotFound;
         return(JsonNet("Organization responsibility does not exist."));
     }
     else
     {
         return(JsonNet(this.GetErrorsForJson()));
     }
 }