Пример #1
0
 public static StudyTask ToDBObject(this StudyTaskService task)
 {
     return(new StudyTask()
     {
         Name = task.Name,
         UserId = task.UserId,
         Estimate = task.Estimate.Ticks
     });
 }
Пример #2
0
 /// <summary> Updates the task in the database with the specified properties. </summary>
 public void UpdateTask(StudyTaskService messageObject)
 {
     using (var context = new StudyTasksContext())
     {
         var dbElement = context.Tasks.FirstOrDefault(taskDB => taskDB.Id == messageObject.Id);
         Contract.Assert(dbElement != null, "Cannot update an element that does not exist");
         dbElement.Name     = messageObject.Name;
         dbElement.Estimate = messageObject.Estimate.Ticks;
         Contract.Assert(dbElement.UserId == messageObject.UserId);
         context.SaveChanges();
     }
 }
Пример #3
0
        /// <summary>
        /// Add a task to the database
        /// </summary>
        /// <param name="task">The task to add</param>
        /// <returns>The id of the task in the database</returns>
        public int Add(StudyTaskService task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            using (var context = new StudyTasksContext())
            {
                var result = context.Tasks.Add(task.ToDBObject());
                if (result == null)
                {
                    throw new NotImplementedException();
                }

                var saveChangeResult = context.SaveChanges();

                return(result.Id);
            }
        }