public HttpResponseMessage CreateVolunteerTask(VolunteerTaskInfo task)
        {
            try
            {
                var timeStamp = DateTime.Now;

                task.CreatedByDate = timeStamp;
                task.CreatedByUserId = UserInfo.UserID;
                task.LastUpdatedByDate = timeStamp;
                task.LastUpdatedByUserId = UserInfo.UserID;

                VolunteerTaskDataAccess.CreateItem(task);

                var savedTask =
                    VolunteerTaskDataAccess.GetItems(task.VolunteerId)
                        .OrderByDescending(t => t.CreatedByDate)
                        .FirstOrDefault();

                var response = new ServiceResponse<VolunteerTaskInfo> { Content = savedTask };

                return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson());
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE);
            }
        }
 public void UpdateItem(VolunteerTaskInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <VolunteerTaskInfo>();
         rep.Update(i);
     }
 }
 public void DeleteItem(VolunteerTaskInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<VolunteerTaskInfo>();
         rep.Delete(i);
     }
 }
        public VolunteerTaskInfo GetItem(int itemId, int volunteerId)
        {
            VolunteerTaskInfo i = null;

            using (IDataContext ctx = DataContext.Instance())
            {
                var rep = ctx.GetRepository <VolunteerTaskInfo>();
                i = rep.GetById(itemId, volunteerId);
            }
            return(i);
        }
예제 #5
0
 public void UpdateItem(VolunteerTaskInfo i)
 {
     repo.UpdateItem(i);
 }
예제 #6
0
 public void DeleteItem(VolunteerTaskInfo i)
 {
     repo.DeleteItem(i);
 }
예제 #7
0
 public void CreateItem(VolunteerTaskInfo i)
 {
     repo.CreateItem(i);
 }
        public HttpResponseMessage UpdateVolunteerTask(VolunteerTaskInfo task)
        {
            try
            {
                var updatesToProcess = false;
                var originalTask = VolunteerTaskDataAccess.GetItem(task.VolunteerTaskId, task.VolunteerId);

                if (!string.Equals(originalTask.Title, task.Title))
                {
                    originalTask.Title = task.Title;
                    updatesToProcess = true;
                }

                if (originalTask.BeginDate != task.BeginDate)
                {
                    originalTask.BeginDate = task.BeginDate;
                    updatesToProcess = true;
                }

                if (originalTask.EndDate != task.EndDate)
                {
                    originalTask.EndDate = task.EndDate;
                    updatesToProcess = true;
                }

                if (originalTask.Completed != task.Completed)
                {
                    originalTask.Completed = task.Completed;
                    updatesToProcess = true;
                }

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

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

                if (updatesToProcess)
                {
                    originalTask.LastUpdatedByDate = DateTime.Now;
                    originalTask.LastUpdatedByUserId = UserInfo.UserID;

                    VolunteerTaskDataAccess.UpdateItem(originalTask);
                }

                var savedTask = VolunteerTaskDataAccess.GetItem(task.VolunteerTaskId, task.VolunteerId);

                var response = new ServiceResponse<VolunteerTaskInfo> { Content = savedTask };

                return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson());
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE);
            }
        }
 public void DeleteItem(VolunteerTaskInfo i)
 {
     repo.DeleteItem(i);
 }
 public void CreateItem(VolunteerTaskInfo i)
 {
     repo.CreateItem(i);
 }
 public void UpdateItem(VolunteerTaskInfo i)
 {
     repo.UpdateItem(i);
 }