コード例 #1
0
 public void DeleteItem(VolunteerInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<VolunteerInfo>();
         rep.Delete(i);
     }
 }
コード例 #2
0
 public void UpdateItem(VolunteerInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <VolunteerInfo>();
         rep.Update(i);
     }
 }
コード例 #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);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
 public void DeleteItem(VolunteerInfo i)
 {
     repo.DeleteItem(i);
 }
コード例 #6
0
 public void CreateItem(VolunteerInfo i)
 {
     repo.CreateItem(i);
 }
コード例 #7
0
 public void UpdateItem(VolunteerInfo i)
 {
     repo.UpdateItem(i);
 }
コード例 #8
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);
 }
コード例 #9
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);
            }
        }