Ejemplo n.º 1
0
        public async Task <IActionResult> AddProject(ProjectForAdd projectForAddDto, int userId)
        {
            var projectForAdd = mapper.Map <Project>(projectForAddDto);

            projectForAdd.Owner = userId;

            repositoryWrapper.ProjectRepository.Add(projectForAdd);

            if (await repositoryWrapper.SaveAll())
            {
                var userProject = new UserProject
                {
                    ProjectId = projectForAdd.ProjectId,
                    UserId    = userId,
                    Status    = "active"
                };

                repositoryWrapper.ProjectRepository.Add(userProject);

                if (await repositoryWrapper.SaveAll())
                {
                    var projectForReturn = mapper.Map <ProjectForReturnAdded>(projectForAdd);
                    return(CreatedAtRoute("GetProject", new { userId, projectForAdd.ProjectId }, projectForReturn));
                }
            }

            return(BadRequest("Could not add project."));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ChangePhoto(int userId, int photoId)
        {
            var user = await userManager.FindByIdAsync(userId.ToString());

            if (user == null)
            {
                return(NotFound("Could not find user."));
            }

            user.PhotoId = photoId;

            if (await repositoryWrapper.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Could not change photo."));
        }
Ejemplo n.º 3
0
        public async Task<IActionResult> AddMessage(int userId, [FromQuery]string recipientNick, MessageForAdd messageForAddDto)
        {               
            var recipient = await repositoryWrapper.UserRepository.GetUserByNick(recipientNick);

            if (recipient == null)
            {
                return NotFound("User with this nickname do not exist.");
            }
               
            var messageToAdd = mapper.Map<Message>(messageForAddDto);

            messageToAdd.SenderId = userId;
            messageToAdd.RecipientId = recipient.Id;

            repositoryWrapper.MessageRepository.Add(messageToAdd);

            if (await repositoryWrapper.SaveAll())
            {
                return Ok();
            }
             
            return BadRequest("Could not send message.");
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddTask(int userId, int projectId, TaskForAdd taskForAdd)
        {
            var project = await repositoryWrapper.ProjectRepository.GetProject(projectId);

            if (project == null)
            {
                return(NotFound("Could not find project."));
            }

            var taskToAdd = mapper.Map <PTask>(taskForAdd);

            taskToAdd.Status = "To Do";
            taskToAdd.Owner  = userId;

            project.PTasks.Add(taskToAdd);

            if (await repositoryWrapper.SaveAll())
            {
                var taskForReturn = mapper.Map <TaskForReturn>(taskToAdd);
                return(CreatedAtRoute("GetTask", new { userId, projectId, taskId = taskToAdd.PTaskId }, taskForReturn));
            }

            return(BadRequest("Could not add task."));
        }