Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,DeadlineDate,DeadlineTime,Priority")] CreateTaskDto givenTask)
        {
            if (ModelState.IsValid)
            {
                var now = DateTime.Now;
                if (givenTask.DeadlineDate + givenTask.DeadlineTime < now)
                {
                    return(View());
                }
                var task = new Task
                {
                    CreatedAt         = DateTime.Now,
                    ApplicationUserId = _userManager.GetUserId(User),
                    Deadline          = givenTask.DeadlineDate.Date + givenTask.DeadlineTime,
                    Priority          = givenTask.Priority,
                    Description       = givenTask.Description,
                    Title             = givenTask.Title,
                };
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemplo n.º 2
0
        // GET: Tasks/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var task = await _context.Tasks.FindAsync(id);

            if (task == null)
            {
                return(NotFound());
            }

            var taskDto = new CreateTaskDto
            {
                Priority     = task.Priority,
                DeadlineDate = task.Deadline.Date,
                DeadlineTime = task.Deadline.TimeOfDay,
                Description  = task.Description,
                Title        = task.Title
            };

            return(View(taskDto));
        }
        public async Task <UserTask> CreateTask(CreateTaskDto createTaskDto)
        {
            User userResult;

            if (createTaskDto.UserId == 0)
            {
                userResult = null;
            }
            else
            {
                userResult = await _taskContext.Users.FirstOrDefaultAsync(x => x.UserId == createTaskDto.UserId);
            }
            UserTask userTask = new UserTask()
            {
                TaskName        = createTaskDto.TaskName,
                TaskDescription = createTaskDto.TaskDescription,
                StartDate       = createTaskDto.StartDate,
                EndDate         = createTaskDto.EndDate,
                Status          = TaskStatus.Active.ToString(),
                IsOpen          = true,
                user            = userResult
            };
            var taskResult = await _taskContext.UserTasks.AddAsync(userTask);

            await _taskContext.SaveChangesAsync();

            return(taskResult.Entity);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateTask([FromBody] CreateTaskDto taskDto)
        {
            try
            {
                if (taskDto == null)
                {
                    _logger.LogError("Object sent from client is null.");
                    return(BadRequest("Owner object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid object sent from client.");
                    return(BadRequest("Invalid model object"));
                }
                await _taskRepository.CreateAsync(new TaskEntity
                {
                    PartitionKey = taskDto.ProjectId,
                    RowKey       = Guid.NewGuid().ToString().Substring(1, 7),
                    Name         = taskDto.Name,
                    Description  = taskDto.Description
                });

                return(Created("", taskDto));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside task Create action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Exemplo n.º 5
0
 public void CreateSprintTask(CreateTaskDto createTaskDto)
 {
     try
     {
         var task = new SprintTask
         {
             Title       = createTaskDto.Title,
             Description = createTaskDto.Description,
             DeveloperId = createTaskDto.DeveloperId,
             SprintId    = createTaskDto.SprintId,
             status      = Status.Pendding
         };
         Db.SprintTasks.Add(task);
         Db.SaveChanges();
         var developers = Db.Developers.Where(x => x.Id == createTaskDto.DeveloperId).SingleOrDefault();
         mail.SendMail(
             developers.Email,
             developers.FirstName,
             "A New Task has been Created <br/>" +
             "Title : " + createTaskDto.Title + "<br/>" +
             "Description : " + createTaskDto.Description + "<br/>" +
             "Best luck PMS bot"
             );
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 6
0
        public async Task CreateAsync_GroupIdAndValidData_CreatesTask()
        {
            //Arrange
            var sut = CreateSut();
            var dto = new CreateTaskDto("name", Guid.NewGuid(), DateTime.Now.AddDays(1));

            Tools.SetupCurrentUserService(_mocker);

            var taskId = Guid.NewGuid();

            var task = new Mock <ITaskEntity>();

            task.SetupGet(o => o.Name).Returns(dto.Name);
            task.SetupGet(o => o.Id).Returns(taskId);
            task.SetupGet(o => o.GroupId).Returns(dto.GroupId);
            task.SetupGet(o => o.Deadline).Returns(dto.Deadline);

            _mocker.GetMock <IEntityValidator>()
            .Setup(o => o.IsGroupIdValidAsync(dto.GroupId.Value))
            .ReturnsAsync(true);

            _mocker.GetMock <ITaskAggregate>()
            .Setup(o => o.Create(dto.Name, Tools.User.Id, dto.GroupId, dto.Deadline))
            .Returns(task.Object);

            //Act
            var result = await sut.CreateAsync(dto);

            //Assert
            result.GroupId.ShouldBe(dto.GroupId);
            result.Id.ShouldBe(task.Object.Id);
            result.Name.ShouldBe(dto.Name);
            result.IsComplete.ShouldBeFalse();
            result.Deadline.ShouldBe(dto.Deadline);
        }
Exemplo n.º 7
0
        public async Task <IActionResult> CreateTask(CreateTaskDto task)
        {
            await userService.CreateTaskAsync(task.Content, task.Due, Int32.Parse(httpContextAccessor.HttpContext.User
                                                                                  .FindFirst("Id").Value));

            return(Ok());
        }
Exemplo n.º 8
0
        public async Task <TaskDto> CreateAsync(CreateTaskDto createTaskDto)
        {
            var taskListEntity = await _tripFlipDbContext.TaskLists
                                 .AsNoTracking()
                                 .SingleOrDefaultAsync(t => t.Id == createTaskDto.TaskListId);

            EntityValidationHelper
            .ValidateEntityNotNull(taskListEntity, ErrorConstants.TaskListNotFound);

            // Validate current user has route 'Admin' role.
            await EntityValidationHelper.ValidateCurrentUserRouteRoleAsync(
                currentUserService : _currentUserService,
                tripFlipDbContext : _tripFlipDbContext,
                routeId : taskListEntity.RouteId,
                routeRoleToValidate : RouteRoles.Admin,
                errorMessage : ErrorConstants.NotRouteAdmin);

            var taskEntity = _mapper.Map <TaskEntity>(createTaskDto);

            await _tripFlipDbContext.Tasks.AddAsync(taskEntity);

            await _tripFlipDbContext.SaveChangesAsync();

            var taskDto = _mapper.Map <TaskDto>(taskEntity);

            return(taskDto);
        }
Exemplo n.º 9
0
        public async Task <IActionResult> CreateTask([FromBody] CreateTaskDto data)
        {
            var session = HttpContext.Session.GetComplexData <UserViewModel>("logged_user_data");

            if (session == null)
            {
                return(RedirectToAction("Index", "Login"));
            }

            var task = _mapper.Map <scrum_ui.Models.Task>(data);

            task.UserId = session.Id;

            await _taskRepository.CreateTask(task);

            var tasks = await _taskRepository.GetTasksByGroupId(task.GroupId);

            int totalScore = 0;

            foreach (var item in tasks)
            {
                if (item.Score != null)
                {
                    totalScore += item.Score.Value;
                }
            }

            return(Json(new { Result = new { Task = task, TotalScore = totalScore, Count = tasks.Count } }));
        }
Exemplo n.º 10
0
        public async Task RemoveTask_GivenAnExistingTask_ShouldRemoveTask()
        {
            var taskToRemove = new CreateTaskDto
            {
                AttendantId = ADMIN_PERSON_ID,
                AuthorId    = ADMIN_PERSON_ID,
                Title       = "new task",
                Description = "new task",
                StatusId    = 1,
                PriorityId  = 1
            };

            var newTaskReq = await DoPostRequest("api/task/newtask", taskToRemove);

            newTaskReq.EnsureSuccessStatusCode();

            var newTaskResp = GetSingleResult <CreateTaskDto>(await newTaskReq.Content.ReadAsStringAsync());

            var removeTaskReq = await DoPostRequest("api/task/removetask", newTaskResp.TaskId);

            removeTaskReq.EnsureSuccessStatusCode();

            var removeTaskResp = GetStructResult <bool>(await removeTaskReq.Content.ReadAsStringAsync());

            Assert.AreEqual(HttpStatusCode.OK, removeTaskReq.StatusCode);
            Assert.IsTrue(removeTaskResp);
        }
Exemplo n.º 11
0
        public IActionResult CreateTask(CreateTaskDto createTaskDto)
        {
            var title = createTaskDto.Title;

            teamLeaderRepository.CreateSprintTask(createTaskDto);
            mail.SendMailForATask("*****@*****.**", "mohammad yahya ", User.Identity.Name, title);
            return(Redirect("ShowProject"));
        }
Exemplo n.º 12
0
        public async Task <CreateTaskDto> CreateNewTask(CreateTaskDto task)
        {
            var eTask = mapper.Map <Core.Entities.Task>(task);

            await taskRepository.Create(eTask);

            return(await taskRepository.SaveChanges() ? task : null);
        }
Exemplo n.º 13
0
        public long CreateTask(CreateTaskDto createTask)
        {
            var command = createTask.ToCommand();

            _commandDispatcher.Handle(command);

            return(command.CreatedTaskId);
        }
Exemplo n.º 14
0
        public Task CreateTask(CreateTaskDto taskDto)
        {
            var task = _mapper.Map <Task>(taskDto);

            _unitOfWork.Repository <Task>().Add(task);
            _unitOfWork.Complete();
            return(task);
        }
Exemplo n.º 15
0
        public async Task <ActionResult <TaskDto> > PostTask(CreateTaskDto createTaskDto)
        {
            var taskEntity = TaskMapper.mapFromCreateTask(createTaskDto);

            _context.Tasks.Add(taskEntity);
            await _context.SaveChangesAsync();

            return(Ok(TaskMapper.mapToDto(taskEntity)));
        }
Exemplo n.º 16
0
        public async Task <ActionResult <TaskDto> > CreateTask(CreateTaskDto createTaskDto)
        {
            var task = await _taskService.CreateTaskAsync(createTaskDto);

            if (task == null)
            {
                return(BadRequest());
            }
            return(Ok(MapTaskToTaskDto(task)));
        }
Exemplo n.º 17
0
        //Assign Task , with dropdown
        public async System.Threading.Tasks.Task Create(CreateTaskDto input)
        {
            var task = ObjectMapper.Map <Task>(input);

            if (task == null)
            {
                throw new UserFriendlyException("No data, Task cannot be created");
            }
            await _taskRepo.InsertAsync(task);
        }
        public void CreateSprintTask(CreateTaskDto createTask)
        {
            var task = new SprintTask
            {
                Title       = createTask.Title,
                Description = createTask.Description
            };

            db.SprintTasks.Add(task);
            db.SaveChanges();
        }
Exemplo n.º 19
0
        public static Task mapFromCreateTask(CreateTaskDto createTaskDto)
        {
            Task result = new Task();

            result.Title       = createTaskDto.Title;
            result.Description = createTaskDto.Description;
            result.Added       = createTaskDto.Added;
            result.Deadline    = createTaskDto.Deadline;
            result.Importance  = (Importance)Enum.Parse(typeof(Importance), createTaskDto.Importance);
            result.State       = (State)Enum.Parse(typeof(State), createTaskDto.State);;
            return(result);
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Post(CreateTaskDto taskDto)
        {
            var taskEntity = SimpleMapper.Map <CreateTaskDto, TaskEntity>(taskDto);

            var createdId = await _taskService.CreateAsync(taskEntity);

            if (createdId == Guid.Empty)
            {
                return(BadRequest());
            }
            return(Ok(createdId));
        }
Exemplo n.º 21
0
        protected override async Task SendDtoAsync(CreateTaskDto dto)
        {
            var updateResult = await _tasksService.UpdateTaskAsync(dto as UpdateTaskDto);

            if (!updateResult.IsSuccess)
            {
                ShowToast(updateResult.GetFullMessage());
                return;
            }

            TaskSaved?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 22
0
 public TaskControllerTests()
 {
     newTask = new CreateTaskDto
     {
         AttendantId = ADMIN_PERSON_ID,
         AuthorId    = ADMIN_PERSON_ID,
         Title       = "new task",
         Description = "new task",
         StatusId    = 1,
         PriorityId  = 1
     };
 }
Exemplo n.º 23
0
        public async Task <IActionResult> Create([FromBody] CreateTaskDto dto)
        {
            //not sure if this is the best way but can't think of a better way.
            var usecase  = new TaskCreatedUseCase(_taskRepository, _lifetimeScope.Resolve <ILogger <TaskCreatedUseCase> >());
            var response = await usecase.Process(_mapper.Map <CreateTaskRequest>(dto));

            if (response.Success)
            {
                return(new OkResult());
            }

            return(ApiHelpers.GetErrorResult(response.Errors, _mapper));
        }
Exemplo n.º 24
0
        public async Task <ActionResult <IEnumerable <User> > > CreateTask(CreateTaskDto createTaskDto)
        {
            try
            {
                await _taskContext.CreateTask(createTaskDto);

                return(Ok(createTaskDto));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error while adding user task data to the database"));
            }
        }
 public IActionResult InsertTask(CreateTaskDto taskDto)
 {
     if (ModelState.IsValid)
     {
         taskDto.SprintID = _sprintId;
         taskRepository.InsertTask(taskDto);
         return(RedirectToAction("ShowSprintTasks", new { @sprintId = _sprintId }));
     }
     else
     {
         return(RedirectToAction("Create"));
     }
 }
Exemplo n.º 26
0
        public async Task CreateNewTask_GivenAnInvalidTaskData_ShouldReturnBadRequest()
        {
            newTask = new CreateTaskDto
            {
                AttendantId = ADMIN_PERSON_ID,
                AuthorId    = ADMIN_PERSON_ID,
                StatusId    = 1,
                PriorityId  = 1
            };

            var response = await DoPostRequest("api/task/newtask", newTask);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        //Add A new Task
        public void CreateSprintTask(CreateTaskDto createTask)
        {
            var task = new SprintTask
            {
                Title       = createTask.Title,
                Description = createTask.Description,
                status      = Status.Pendding,
                DeveloperId = createTask.DeveloperId,
                SprintId    = createTask.SprintId
            };

            db.SprintTasks.Add(task);
            db.SaveChanges();
        }
Exemplo n.º 28
0
        public async Task <TaskDto> CreateAsync(CreateTaskDto dto)
        {
            if (dto.GroupId is not null && !await _entityValidator.IsGroupIdValidAsync(dto.GroupId.Value))
            {
                throw new GroupIdInvalidException();
            }

            var userId = _currentUserService.GetCurrentUser().Id;

            var task = _taskAggregate.Create(dto.Name, userId, dto.GroupId, dto.Deadline);

            await _taskRepository.CreateAsync(task);

            return(new(task.Id, task.Name, task.Created, task.IsComplete, task.GroupId, task.Deadline));
        }
Exemplo n.º 29
0
        public async Task <int> Post([FromBody] CreateTaskDto value)
        {
            var task = mapper.Map <PTask>(value);

            task.TaskUsers = userService.GetAll()
                             .Where(x => value.UserNames.Contains(x.UserName))
                             .Select(user => new PTaskUser {
                UserId = user.Id, Task = task
            })
                             .ToList();

            await taskService.Create(task);

            return(task.Id);
        }
Exemplo n.º 30
0
        public void InsertTask(CreateTaskDto tasktDto)
        {
            SprintTask task = new SprintTask()
            {
                SprintID    = tasktDto.SprintID,
                Title       = tasktDto.Title,
                Description = tasktDto.Description,
                Status      = Status.PendingApproval,
                StartDate   = tasktDto.StartDate,
                EndDate     = tasktDto.EndDate,
                DeveloperID = tasktDto.DeveloperId
            };

            context.SprintTasks.Add(task);
            context.SaveChanges();
        }