Ejemplo n.º 1
0
        }//UpdateDBData ends

        /// <summary>
        /// Public method that is in charge to add records to the TASK table.
        /// </summary>
        public void CreateTask(Persistence.Task Task)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var task = new Persistence.Task
                    {
                        Task_Description = Task.Task_Description,
                        Task_Date        = DateTime.Today,
                    };
                    connection.Tasks.Add(task);

                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (DbUpdateException e)
            {
                var exception = Util.HandleDbUpdateException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }//create task ends
Ejemplo n.º 2
0
        public void TestAddTask()
        {
            try
            {
                var data = new List <ProjectManager.Persistence.Task>()
                {
                }.AsQueryable();

                var mockSet = new Mock <DbSet <ProjectManager.Persistence.Task> >();
                mockSet.As <IQueryable <ProjectManager.Persistence.Task> >().Setup(m => m.Provider).Returns(data.Provider);
                mockSet.As <IQueryable <ProjectManager.Persistence.Task> >().Setup(m => m.Expression).Returns(data.Expression);
                mockSet.As <IQueryable <ProjectManager.Persistence.Task> >().Setup(m => m.ElementType).Returns(data.ElementType);
                mockSet.As <IQueryable <ProjectManager.Persistence.Task> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
                mockSet.As <IQueryable <ProjectManager.Persistence.Task> >().Setup(m => m.Provider).Returns(data.Provider);

                Task Task = new Persistence.Task {
                    ProjectId = 25, TaskName = "Support Test Driven Development", IsParentTask = true, Priority = 2, ParentTask = 5, StartDate = new DateTime(2018, 8, 12), EndDate = DateTime.Now, UserId = 20
                };

                var mockContext = new Mock <ProjectManagerContext>();
                mockContext.Setup(m => m.tasks).Returns(mockSet.Object);

                var         service  = new TaskRepository(mockContext.Object);
                List <Task> TaskList = service.GetAllTasks();

                Assert.That(TaskList.Count == 0);
                bool ret = service.AddTask(Task);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Assert.That(1 == 0);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Public method that queries the task table from the data base to get the record
        /// that matches the Task_ID.
        /// </summary>
        /// <param name="idTask"> Task_ID, Type INT </param>

        public void UpdateDBData(int idTask, Persistence.Task Task)
        {
            try
            {
                using (var connection = new Persistence.LHEntities())
                {
                    var task = connection.Tasks
                               .Where(t => t.Task_ID == idTask)
                               .FirstOrDefault();
                    task.Task_Description = Task.Task_Description;
                    task.Task_Date        = Task.Task_Date;
                    connection.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var exception = Util.HandleDbEntityValidationException(e);
                throw exception;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }//UpdateDBData ends