Ejemplo n.º 1
0
        public HttpResponseMessage GetVolunteers(int codeCampId)
        {
            try
            {
                var volunteers = VolunteerDataAccess.GetItems(codeCampId);

                volunteers = LoadSupplementalProperties(volunteers);

                var response = new ServiceResponse <List <VolunteerInfo> > {
                    Content = volunteers.ToList()
                };

                if (volunteers == null)
                {
                    ServiceResponseHelper <List <VolunteerInfo> > .AddNoneFoundError("volunteers", ref response);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
Ejemplo n.º 2
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));
            }
        }
Ejemplo n.º 3
0
 private void LoadSupplementalProperties(ref VolunteerInfo volunteer)
 {
     volunteer.TasksClosed  = VolunteerTaskDataAccess.GetVolunteerTaskCount(volunteer.VolunteerId, Globals.TASKSTATE_CLOSED);
     volunteer.TasksOpen    = VolunteerTaskDataAccess.GetVolunteerTaskCount(volunteer.VolunteerId, Globals.TASKSTATE_OPEN);
     volunteer.TasksOverdue = VolunteerTaskDataAccess.GetVolunteerTaskCount(volunteer.VolunteerId, Globals.TASKSTATE_OVERDUE);
     volunteer.FullName     = VolunteerDataAccess.GetItemFullName(volunteer.VolunteerId, volunteer.CodeCampId, PortalSettings.PortalId);
 }
Ejemplo n.º 4
0
        private VolunteerInfo GenerateOrganizerVolunteerInfo(int codeCampId)
        {
            var registration = RegistrationDataAccess.GetItemByUserId(UserInfo.UserID, codeCampId);

            if (registration == null)
            {
                RegistrationDataAccess.CreateItem(new RegistrationInfo()
                {
                    CodeCampId       = codeCampId,
                    IsRegistered     = true,
                    Notes            = "Registered automatically by Volunteer view.",
                    RegistrationDate = DateTime.Now,
                    ShirtSize        = "XL",
                    UserId           = UserInfo.UserID
                });

                registration = RegistrationDataAccess.GetItemByUserId(UserInfo.UserID, codeCampId);
            }

            VolunteerDataAccess.CreateItem(new VolunteerInfo()
            {
                CodeCampId     = codeCampId,
                Notes          = "Automatically generated by the Volunteer view.",
                RegistrationId = registration.RegistrationId
            });

            return(VolunteerDataAccess.GetItemByRegistrationId(registration.RegistrationId, codeCampId));
        }
Ejemplo n.º 5
0
        public HttpResponseMessage DeleteVolunteer(int itemId, int codeCampId)
        {
            try
            {
                VolunteerDataAccess.DeleteItem(itemId, codeCampId);

                var response = new ServiceResponse <string> {
                    Content = SUCCESS_MESSAGE
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
Ejemplo n.º 6
0
        public HttpResponseMessage CreateVolunteer(VolunteerInfo volunteer)
        {
            try
            {
                VolunteerDataAccess.CreateItem(volunteer);

                var savedVolunteer = VolunteerDataAccess.GetItemByRegistrationId(volunteer.RegistrationId, 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));
            }
        }
Ejemplo n.º 7
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));
            }
        }