Esempio n. 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)));
        }
Esempio n. 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());
        }
Esempio n. 3
0
        public IActionResult GetTeam(int teamId)
        {
            var team = _repo.GetTeam(teamId);

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

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

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

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

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

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

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

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

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

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

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

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

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

            return(Ok(ModelsMapping.GetSickLeaveDto(sickLeave)));
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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)));
        }
Esempio n. 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));
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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)));
        }
Esempio n. 23
0
 public IActionResult GetUsers()
 {
     return(Ok(_repo.GetUsers().Select(o => ModelsMapping.GetUserDto(o))));
 }