示例#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 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)));
        }
示例#3
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)));
        }