Пример #1
0
        public async Task <IActionResult> AddTask([FromBody] Task task)
        {
            task.Creator = _unitOfWork.UserRepository.Get(x => x.UId == task.Creator.UId).FirstOrDefault();

            var tags = task.Tags.Select(y => y.Tag);

            var tagsFromBd = _unitOfWork.TagRepository.Get(x => tags.Contains(x));

            var taskTags = tagsFromBd.Select(x => new TaskTag()
            {
                Tag = x
            }).ToList();

            task.Tags = taskTags;

            var assigned = task.AssignedTo.Select(x => x.Member);

            var assignedFromBd = _unitOfWork.UserRepository.Get(x => assigned.Contains(x));

            var taskMembers = assignedFromBd.Select(x => new TaskMember()
            {
                Member = x
            }).ToList();

            task.AssignedTo = taskMembers;

            _unitOfWork.TaskRepository.Insert(task);

            await _unitOfWork.Save();

            return(Ok(LoadProject(task.ProjectId)));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("id,title,notes,startDate,endDate,isCompleted")] TaskManager.Models.Task task)
        {
            if (id != task.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(task);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TaskExists(task.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }
Пример #3
0
        public int Save(Task task)
        {
            Task dbTask;

            if (task.Id > 0)
            {
                dbTask = _db.Tasks.Find(task.Id);
                if (dbTask != null)
                {
                    dbTask.Name         = task.Name;
                    dbTask.ModifiedDate = DateTime.Now;
                    dbTask.DueDate      = task.DueDate;
                }
            }
            else
            {
                task.EntryDate    = DateTime.Now;
                task.ModifiedDate = DateTime.Now;
                dbTask            = _db.Tasks.Add(task);
            }


            _db.SaveChanges();
            return(dbTask.Id);
        }
Пример #4
0
 public async Task <IActionResult> Edit(Task task)
 {
     if (ModelState.IsValid)
     {
         _context.Update(task);
         await _context.SaveChangesAsync();
     }
     return(RedirectToAction("Index", new { selectedTaskId = task.Id }));
 }
Пример #5
0
 public ActionResult Edit(Task model)
 {
     if (ModelState.IsValid)
     {
         _repository.Update(model);
         return RedirectToAction("Index", "Task");
     }
     return View(model);
 }
Пример #6
0
        public async Task <IActionResult> DeleteTask([FromBody] Task deletedTask)
        {
            var task = _unitOfWork.TaskRepository.Get(x => x.Id == deletedTask.Id).FirstOrDefault();

            _unitOfWork.TaskRepository.Delete(task);

            await _unitOfWork.Save();

            return(Ok(LoadProject(task.ProjectId)));
        }
Пример #7
0
        public bool Delete(int id)
        {
            Task task = _db.Tasks.Find(id);

            if (task != null)
            {
                _db.Tasks.Remove(task);
                _db.SaveChanges();
            }
            return(true);
        }
Пример #8
0
 public ActionResult Create(Task newTask)
 {
     if (ModelState.IsValid)
     {
         //give the task a new id
         newTask.Id = DateTime.Now.Ticks;
         _repository.Add(newTask);
         return RedirectToAction("Index", "Task"); //if the controller is ommited, it will be empty during testing
     }
     return View(newTask);
 }
Пример #9
0
 public async Task <IActionResult> Create(Task task)
 {
     if (ModelState.IsValid)
     {
         task.Id = 0;
         task.DateOfRegistration = DateTime.Now;
         task.TaskStatus         = TaskStatus.Appointed;
         _context.Add(task);
         await _context.SaveChangesAsync();
     }
     return(RedirectToAction("Index", new { selectedTaskId = task.Id }));
 }
        public void DeleteButton(TaskManager.Models.Task task)
        {
            if (LoggedUser.Instance.IsManager())
            {
                Show.DeleteTaskBox(task);

                this.Tasks = (List <Task>)Repository.Instance.Tasks;
                this.NotifyOfPropertyChange(() => this.Tasks);
            }
            else
            {
                Show.ErrorBox("Nie masz uprawnień do usuwania zadań!");
            }
        }
Пример #11
0
        public Task GetById(int id)
        {
            var task = _db.Tasks.Find(id);

            Task result = new Task()
            {
                DueDate      = task.DueDate.Date,
                EntryDate    = task.EntryDate,
                Id           = task.Id,
                ModifiedDate = task.ModifiedDate,
                Name         = task.Name
            };

            return(result);
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("id,title,notes,startDate,endDate")] TaskManager.Models.Task task)
        {
            if (ModelState.IsValid)
            {
                if (task.startDate >= task.endDate)
                {
                    return(Json($"A user named already exists."));
                }

                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }
Пример #13
0
        public void Create_WhenAddingAValidTaskIsSuccessful_ReturnsToTaskIndex()
        {
            //ARRANGE: Create a mock that expectcs a call to Repository.Add
            var newTask = new Task { Id = 1, Description = "Task 1", IsCompleted = false };
            var mock = new Mock<IRepository<Task>>();
            mock.Setup(x => x.Add(newTask));
            var repository = mock.Object;

            var controller = new TaskController(repository);

            //ACT:
            RedirectToRouteResult result = (RedirectToRouteResult)controller.Create(newTask);

            //ASSERT:
            Assert.IsNotNull(result);
            Assert.AreEqual("Task", result.RouteValues["Controller"]);
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
Пример #14
0
        public async Task <IActionResult> UpdateTask([FromBody] Task updatedTask)
        {
            var task = _unitOfWork.TaskRepository.Get(x => x.Id == updatedTask.Id).FirstOrDefault();

            task.Name = updatedTask.Name;

            task.Details = updatedTask.Details;

            task.IsPriority = updatedTask.IsPriority;

            task.IsSpecial = updatedTask.IsSpecial;

            _unitOfWork.TaskRepository.Update(task);

            await _unitOfWork.Save();

            return(Ok(LoadProject(task.ProjectId)));
        }
Пример #15
0
        public async Task <IActionResult> Create(int?parentId)
        {
            var newTask = new Task
            {
                EndDate = DateTime.Today
            };

            if (parentId != null)
            {
                newTask.ParentTaskId = parentId;
                var parentTask = await _context.Tasks.SingleOrDefaultAsync(t => t.Id == parentId);

                if (parentTask.TaskStatus == TaskStatus.Completed)
                {
                    return(RedirectToAction("Index", new { selectedTaskId = parentTask.Id, message = "Для завершённых задач нельзя добавлять новые подзачи." }));
                }
                newTask.ListOfPerformers = parentTask.ListOfPerformers;
            }
            return(View(newTask));
        }
Пример #16
0
        public async Task <IActionResult> CompleteChangeTask([FromBody] Task updatedTask)
        {
            var task = _unitOfWork.TaskRepository.Get(x => x.Id == updatedTask.Id).FirstOrDefault();

            if (!task.IsCompleted)
            {
                var completedBy = _unitOfWork.UserRepository.Get(x => x.UId == updatedTask.CompletedBy.UId).FirstOrDefault();

                task.CompletedBy = completedBy;
            }

            else
            {
                _unitOfWork.TaskRepository.SetNull(task, "CompletedById");
            }

            task.IsCompleted = !task.IsCompleted;

            _unitOfWork.TaskRepository.Update(task);

            await _unitOfWork.Save();

            return(Ok(LoadProject(task.ProjectId)));
        }
Пример #17
0
 public void Post([FromBody] TaskManager.Models.Task task)
 {
     db.Add(task);
     db.SaveChanges();
 }
Пример #18
0
		public long DeleteTask (Task item)
		{
			using (var database = new SQLiteConnection(_helper.WritableDatabase.Path)) {
				return database.Delete(item);
			}
		}
Пример #19
0
		public long AddTask(Task item)
		{
			using (var database = new SQLiteConnection(_helper.WritableDatabase.Path)) {
				return database.Insert(item);
			}
		}
Пример #20
0
        public void Edit_WhenUpdatingIsSuccessful_RedirectsToTasksIndex()
        {
            //ARRANGE
            var task = new Task { Id = 1, Description = "Updated description", IsCompleted = true };

            //ACT
            var result = (RedirectToRouteResult)_controller.Edit(task);

            //ASSERT
            Assert.IsNotNull(result);
            Assert.AreEqual("Task", result.RouteValues["Controller"]);
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
Пример #21
0
		public long SaveTask(Task item)
		{
			return DatabaseManager.AddTask(item);
		}