예제 #1
0
        public IActionResult GetUnclosedWorkingTime(int userId, int taskId)
        {
            if (_repo.GetUser(userId) == null)
            {
                return(NotFound());
            }
            if (_repo.GetTask(taskId) == null)
            {
                return(NotFound());
            }

            var userWorkTimes = _repo.GetWorkTimesForUser(userId);

            if (userWorkTimes == null || !userWorkTimes.Any())
            {
                return(NotFound());
            }

            var unfinishedWorkTime = userWorkTimes.FirstOrDefault(o => !EntitiesUtils.IsDateEmpty(o.WorkStartTime) && EntitiesUtils.IsDateEmpty(o.WorkEndTime));

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

            return(Ok(ModelsMapping.GetWorkTimeDto(unfinishedWorkTime)));
        }
예제 #2
0
        public IActionResult PatchWorkTime(int userId, int workTimeId,
                                           [FromBody] JsonPatchDocument <WorkTimeForPartialUpdateDTO> patchDocument)
        {
            if (_repo.GetUser(userId) == null)
            {
                return(NotFound());
            }
            var workTimeToUpdate = _repo.GetWorkTime(userId, workTimeId);

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

            var workTimeWithUpdatedValues = ModelsMapping.GetWorkTimeForPartialUpdateDto(workTimeToUpdate);

            patchDocument.ApplyTo(workTimeWithUpdatedValues);
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            ValuesUpdater.ApplyPatchToWorkTimeEntity(workTimeToUpdate, workTimeWithUpdatedValues);
            _repo.SaveChanges();
            return(Ok());
        }
예제 #3
0
        public IActionResult GetTeam(int teamId)
        {
            var team = _repo.GetTeam(teamId);

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

            return(Ok(ModelsMapping.GetTeamDto(team)));
        }
예제 #4
0
        public IActionResult GetUser(int userId)
        {
            var user = _repo.GetUser(userId);

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

            return(Ok(ModelsMapping.GetUserDto(user)));
        }
예제 #5
0
        public IActionResult GetVacation(int vacationId)
        {
            var vacations = _repo.GetVacation(vacationId);

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

            return(Ok(ModelsMapping.GetVacationDto(vacations)));
        }
예제 #6
0
        public IActionResult GetComment(int commentId)
        {
            var comment = _repo.GetComment(commentId);

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

            return(Ok(ModelsMapping.GetCommentDto(comment)));
        }
예제 #7
0
        public IActionResult GetPayment(int paymentId)
        {
            var payment = _repo.GetPayment(paymentId);

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

            return(Ok(ModelsMapping.GetPaymentDto(payment)));
        }
예제 #8
0
        public IActionResult GetManagement(int managementId)
        {
            var manager = _repo.GetManager(managementId);

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

            return(Ok(ModelsMapping.GetManagementDto(manager)));
        }
예제 #9
0
        public IActionResult GetSickLeave(int sickLeaveId)
        {
            var sickLeave = _repo.GetSickLeave(sickLeaveId);

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

            return(Ok(ModelsMapping.GetSickLeaveDto(sickLeave)));
        }
예제 #10
0
        public IActionResult PostVacation([FromBody] VacationForCreationDTO vacationFromRequest)
        {
            if (vacationFromRequest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _repo.AddVacation(ModelsMapping.GetVacationEntity(vacationFromRequest));
            return(Ok());
        }
예제 #11
0
        public IActionResult PostComment([FromBody] CommentForCreationDto commentFromRequest)
        {
            if (commentFromRequest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _repo.AddComment(ModelsMapping.GetCommentEntity(commentFromRequest));
            return(Ok());
        }
예제 #12
0
        public IActionResult PostPayment([FromBody] PaymentForCreationDTO paymentFromRequest)
        {
            if (paymentFromRequest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _repo.AddPayment(ModelsMapping.GetPaymentEntity(paymentFromRequest));
            return(Ok());
        }
예제 #13
0
        public IActionResult PostTeam([FromBody] TeamForCreationDTO teamFromRequest)
        {
            if (teamFromRequest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _repo.AddTeam(ModelsMapping.GetTeamEntity(teamFromRequest));
            return(Ok());
        }
예제 #14
0
        public IActionResult PostSickLeave([FromBody] SickLeaveForCreationDTO sickLeaveFromRequest)
        {
            if (sickLeaveFromRequest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _repo.AddSickLeave(ModelsMapping.GetSickLeaveEntity(sickLeaveFromRequest));
            return(Ok());
        }
예제 #15
0
        public IActionResult PostManagement([FromBody] ManagementForCreationDTO managementFromRequest)
        {
            if (managementFromRequest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _repo.AddManager(ModelsMapping.GetManagementEntity(managementFromRequest));
            return(Ok());
        }
예제 #16
0
        public IActionResult AddWorkTime(int userId, [FromBody] WorkTimeForCreationDTO workTimeFromRequest)
        {
            if (_repo.GetUser(userId) == null)
            {
                return(NotFound("User not found"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid model"));
            }

            _repo.AddWorkTime(ModelsMapping.GetWorkTimeEntity(workTimeFromRequest));
            return(Ok());
        }
예제 #17
0
        public IActionResult AddUser([FromBody] UserForCreationDTO userFromRequest)
        {
            if (userFromRequest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            userFromRequest.Password = GetPasswordHash(userFromRequest.Password);

            _repo.AddUser(ModelsMapping.GetUserEntity(userFromRequest));
            return(Ok());
        }
예제 #18
0
        public IActionResult GetWorkTimeForUser(int userId, int workTimeId)
        {
            if (_repo.GetUser(userId) == null)
            {
                return(NotFound());
            }
            var workTime = _repo.GetWorkTime(userId, workTimeId);

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

            return(Ok(ModelsMapping.GetWorkTimeDto(workTime)));
        }
예제 #19
0
        public IActionResult GetSubordinates(int userId)
        {
            var users = _repo.GetUsers().Select(ModelsMapping.GetUserDto);

            if (users == null || !users.Any())
            {
                return(NotFound());
            }

            var currentUser = ModelsMapping.GetUserDto(_repo.GetUser(userId));

            if (currentUser == null)
            {
                return(BadRequest());
            }

            var subordinatesIdsList = new List <int>();

            GetSubordinatesIDs(users, subordinatesIdsList, currentUser);

            return(Ok(subordinatesIdsList));
        }
예제 #20
0
        public IActionResult PatchTask(int taskId, [FromBody] JsonPatchDocument <TaskForPartialUpdateDTO> patchDocument)
        {
            var taskToUpdate = _repo.GetTask(taskId);

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

            var taskWithUpdatedValues = ModelsMapping.GetTaskForPartialUpdateDto(taskToUpdate);

            patchDocument.ApplyTo(taskWithUpdatedValues);
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            ValuesUpdater.ApplyPatchToTaskEntity(taskToUpdate, taskWithUpdatedValues);
            _repo.SaveChanges();

            return(Ok());
        }
예제 #21
0
        public IActionResult PatchUser(int userId, [FromBody] JsonPatchDocument <UserForPartialUpdateDTO> patchDocument)
        {
            var userToUpdate = _repo.GetUser(userId);

            if (userToUpdate == null)
            {
                return(BadRequest());
            }

            var userWithUpdatedValues = ModelsMapping.GetUserForPartialUpdateDto(userToUpdate);

            patchDocument.ApplyTo(userWithUpdatedValues);
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            ValuesUpdater.ApplyPatchToUserEntity(userToUpdate, userWithUpdatedValues);
            _repo.SaveChanges();

            return(Ok());
        }
예제 #22
0
        public IActionResult PutWorkTime(int userId, int workTimeId, [FromBody] WorkTimeForCreationDTO workTimeFromRequest)
        {
            if (workTimeFromRequest == null)
            {
                return(BadRequest("task is null"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest("model is not valid"));
            }

            var workTimeFromDb = _repo.GetWorkTime(userId, workTimeId);

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

            ValuesUpdater.UpdateWorkTimeFromDto(workTimeFromDb, workTimeFromRequest);
            _repo.SaveChanges();

            return(Ok(ModelsMapping.GetWorkTimeDto(workTimeFromDb)));
        }
예제 #23
0
 public IActionResult GetUsers()
 {
     return(Ok(_repo.GetUsers().Select(o => ModelsMapping.GetUserDto(o))));
 }