Beispiel #1
0
        public HttpResponseMessage GetVolunteer(int itemId, int codeCampId)
        {
            try
            {
                var volunteer = VolunteerDataAccess.GetItem(itemId, codeCampId);
                var response  = new ServiceResponse <VolunteerInfo> {
                    Content = volunteer
                };

                if (volunteer == null &&
                    (UserInfo.IsSuperUser || UserInfo.IsInRole(PortalSettings.AdministratorRoleName) ||
                     ModulePermissionController.HasModulePermission(ActiveModule.ModulePermissions, "Edit")))
                {
                    // automatically make superusers, admins, and editors a volunteer
                    response.Content = GenerateOrganizerVolunteerInfo(codeCampId);
                }
                else if (volunteer == null)
                {
                    ServiceResponseHelper <VolunteerInfo> .AddNoneFoundError("volunteer", ref response);
                }

                if (volunteer != null)
                {
                    LoadSupplementalProperties(ref volunteer);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
Beispiel #2
0
        public HttpResponseMessage UpdateVolunteer(VolunteerInfo volunteer)
        {
            try
            {
                var updatesToProcess  = false;
                var originalVolunteer = VolunteerDataAccess.GetItem(volunteer.VolunteerId, volunteer.CodeCampId);

                if (!string.Equals(volunteer.Notes, originalVolunteer.Notes))
                {
                    originalVolunteer.Notes = volunteer.Notes;
                    updatesToProcess        = true;
                }

                if (originalVolunteer.CustomProperties != null)
                {
                    // parse custom properties for updates
                    foreach (var property in originalVolunteer.CustomPropertiesObj)
                    {
                        if (volunteer.CustomPropertiesObj.Any(p => p.Name == property.Name))
                        {
                            // see if the existing property needs to be updated
                            var prop = volunteer.CustomPropertiesObj.FirstOrDefault(p => p.Name == property.Name);
                            if (!string.Equals(prop.Value, property.Value))
                            {
                                property.Value   = prop.Value;
                                updatesToProcess = true;
                            }
                        }
                        else
                        {
                            // delete the property
                            originalVolunteer.CustomPropertiesObj.Remove(property);
                            updatesToProcess = true;
                        }
                    }
                }

                if (volunteer.CustomPropertiesObj != null)
                {
                    // add any new properties
                    if (originalVolunteer.CustomProperties == null)
                    {
                        foreach (var property in volunteer.CustomPropertiesObj)
                        {
                            originalVolunteer.CustomPropertiesObj.Add(property);
                            updatesToProcess = true;
                        }
                    }
                    else
                    {
                        foreach (var property in volunteer.CustomPropertiesObj.Where(property => !originalVolunteer.CustomPropertiesObj.Contains(property)))
                        {
                            originalVolunteer.CustomPropertiesObj.Add(property);
                            updatesToProcess = true;
                        }
                    }
                }

                if (updatesToProcess)
                {
                    VolunteerDataAccess.UpdateItem(originalVolunteer);
                }

                var savedVolunteer = VolunteerDataAccess.GetItem(volunteer.VolunteerId, volunteer.CodeCampId);

                var response = new ServiceResponse <VolunteerInfo> {
                    Content = savedVolunteer
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }