Ejemplo n.º 1
0
        public async Task <bool> CreateUserTaskAsync(UserTaskDto userTaskDTO)
        {
            var planTask = await db.PlanTasks.Get(userTaskDTO.PlanTaskId);

            if (planTask == null)
            {
                return(false);
            }
            if (await db.Users.GetAsync(userTaskDTO.UserId) == null)
            {
                return(false);
            }
            var userTask = new UserTask()
            {
                User_Id          = userTaskDTO.UserId,
                PlanTask_Id      = userTaskDTO.PlanTaskId,
                State            = userTaskDTO.State,
                End_Date         = userTaskDTO.EndDate,
                Result           = userTaskDTO.Result,
                Propose_End_Date = userTaskDTO.ProposeEndDate,
                Mentor_Id        = userTaskDTO.MentorId
            };

            db.UserTasks.AddAsync(userTask);
            db.Save();
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create(UserTaskViewModel taskModel)
        {
            if (ModelState.IsValid)
            {
                var _userTaskDto = new UserTaskDto {
                    Name              = taskModel.Name,
                    Description       = taskModel.Description,
                    DueDate           = taskModel.DueDate,
                    ApplicationUserId = User.Identity.GetUserId()
                };
                try {
                    await this._taskService.Create(_userTaskDto);

                    return(RedirectToAction("Index", "Home"));//Add partial "New task was created!"
                } catch (ValidationException ex) {
                    ModelState.AddModelError(ex.Property, ex.Message);
                }
            }
            else
            {
                var _duplicatedModelState = ModelState.Values.SingleOrDefault(ms => ms.Errors.Count > 1 && ms.Errors[0].ErrorMessage == ms.Errors[1].ErrorMessage);
                if (_duplicatedModelState != null)
                {
                    _duplicatedModelState.Errors.Remove(_duplicatedModelState.Errors[1]);
                }
            }
            return(View(taskModel));
        }
        public async Task <HttpResponseMessage> PostNewUserTaskAsync([FromBody] UserTaskDto newUserTask)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
                bool success = await taskService.CreateUserTaskAsync(newUserTask);

                if (success)
                {
                    var message = $"Succesfully created task with id = {newUserTask.Id} for user with id = {newUserTask.UserId}";
                    tracer.Info(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, message);
                    return(Request.CreateResponse(HttpStatusCode.OK, "Succesfully created task for user."));
                }
                tracer.Warn(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, "Error occured on user task creating");
                return(Request.CreateErrorResponse(HttpStatusCode.NoContent, "There is no user or task in database"));
            }
            catch (EntityException e)
            {
                tracer.Error(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, e);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
Ejemplo n.º 4
0
        public async Task PostNewUserTaskTest_ShouldCheckNotValidInputParameterAndReturnBadRequestResponse()
        {
            taskServiceMock.Setup(mts => mts.CreateUserTaskAsync(It.IsAny <UserTaskDto>()))
            .ReturnsAsync(true);

            var newUserTask = new UserTaskDto();

            ValidateViewModel(taskController, newUserTask);
            HttpResponseMessage response = await taskController.PostNewUserTaskAsync(newUserTask);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Ejemplo n.º 5
0
        public UserTaskDto AddTask(UserTaskDto newTask)
        {
            var task = Mapper.Map <UserTask>(newTask);

            task.CreatedAt = DateTime.Now;

            task = context.UserTasks.Add(task);
            context.SaveChanges();
            var taskDto = Mapper.Map <UserTaskDto>(task);

            return(taskDto);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Add(UserTaskDto newUserTask)
        {
            try
            {
                await _tasksService.Add(newUserTask);

                return(Ok());
            }
            catch (DuplicatedTaskTextException e)
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 7
0
        public void UpdateTask(UserTaskDto newTask)
        {
            var task   = Mapper.Map <UserTask>(newTask);
            var dbTask = context.UserTasks.Where(x => x.ID == task.ID).FirstOrDefault();

            if (dbTask != null)
            {
                dbTask.Title       = task.Title;
                dbTask.Description = task.Description;
                dbTask.TargetDate  = task.TargetDate;
                context.SaveChanges();
            }
            else
            {
                throw new KeyNotFoundException("Task not found");
            }
        }
        public async Task Add(UserTaskDto newTask)
        {
            var allTasks = await _taskRepository.GetAll();

            if (allTasks.Any(x => x.Text.Equals(newTask.Text)))
            {
                throw new DuplicatedTaskTextException();
            }

            var task = new UserTask()
            {
                Id        = Guid.NewGuid(),
                Text      = newTask.Text,
                CreatedAt = DateTime.Now
            };

            await _taskRepository.Add(task);
        }
Ejemplo n.º 9
0
        public async Task <UserTaskDto> GetUserTaskByUserPlanTaskIdAsync(int userId, int planTaskId)
        {
            UserTask userTask = await db.UserTasks.GetByPlanTaskForUserAsync(planTaskId, userId);

            if (userTask == null)
            {
                return(null);
            }
            var userTaskDto = new UserTaskDto(userTask.Id,
                                              userTask.User_Id,
                                              userTask.PlanTask_Id,
                                              userTask.End_Date,
                                              userTask.Propose_End_Date,
                                              userTask.Mentor_Id,
                                              userTask.State,
                                              userTask.Result);

            return(userTaskDto);
        }
Ejemplo n.º 10
0
        public async Task Create(UserTaskDto item)
        {
            var _user = await this._tuow.UserManager.FindByIdAsync(item.ApplicationUserId);

            if (_user == null)
            {
                throw new ValidationException("User is not found", "");
            }
            var _task = new UserTask {
                Name              = item.Name,
                Description       = item.Description,
                CreateDate        = DateTime.Now,
                DueDate           = item.DueDate,
                ApplicationUserId = _user.Id
            };

            this._tuow.Tasks.Create(_task);
            await this._tuow.SaveAsync();
        }
Ejemplo n.º 11
0
        public TaskWindow(UserTaskDto task = null)
        {
            if (task == null)
            {
                IsEditMode  = false;
                context     = new TaskWindowModel();
                DataContext = context;
            }
            else
            {
                IsEditMode  = true;
                context     = new TaskWindowModel(task);
                DataContext = context;
            }

            InitializeComponent();
            SetTitle();
            SetVisibilityOfButtons();
            this.PreviewKeyDown += TaskWindow_PreviewKeyDown;
        }
Ejemplo n.º 12
0
        public async Task <HttpResponseMessage> GetUserTaskAsync(int planTaskId, int userId)
        {
            try
            {
                var currentId   = userIdentityService.GetUserId();
                var currentRole = userIdentityService.GetUserRole();
                if (!(userId == currentId || currentRole == Constants.Roles.Mentor))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Authorization denied."));
                }
                UserTaskDto userTask = await taskService.GetUserTaskByUserPlanTaskIdAsync(userId, planTaskId);

                if (userTask != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, userTask));
                }
                return(Request.CreateErrorResponse(HttpStatusCode.NoContent, "Task for this user does not exist in database."));
            }
            catch (EntityException e)
            {
                tracer.Error(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, e);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }