public void DeleteItem(VolunteerInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<VolunteerInfo>();
         rep.Delete(i);
     }
 }
Exemple #2
0
 public void UpdateItem(VolunteerInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <VolunteerInfo>();
         rep.Update(i);
     }
 }
Exemple #3
0
        public VolunteerInfo GetItem(int itemId, int registrationId)
        {
            VolunteerInfo i = null;

            using (IDataContext ctx = DataContext.Instance())
            {
                var rep = ctx.GetRepository <VolunteerInfo>();
                i = rep.GetById(itemId, registrationId);
            }
            return(i);
        }
        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);
            }
        }
Exemple #5
0
 public void DeleteItem(VolunteerInfo i)
 {
     repo.DeleteItem(i);
 }
Exemple #6
0
 public void CreateItem(VolunteerInfo i)
 {
     repo.CreateItem(i);
 }
Exemple #7
0
 public void UpdateItem(VolunteerInfo i)
 {
     repo.UpdateItem(i);
 }
 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);
 }
        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);
            }
        }