Example #1
0
 public static void UpdateWorkTimeFromDto(WorkTime workTimeToUpdate, WorkTimeForCreationDTO workTimeWithUpdatedValues)
 {
     workTimeToUpdate.TaskId        = workTimeWithUpdatedValues.TaskId;
     workTimeToUpdate.UserId        = workTimeWithUpdatedValues.UserId;
     workTimeToUpdate.WorkStartTime = workTimeWithUpdatedValues.WorkStartTime;
     workTimeToUpdate.WorkEndTime   = workTimeWithUpdatedValues.WorkEndTime;
 }
Example #2
0
 public static WorkTime GetWorkTimeEntity(WorkTimeForCreationDTO workTimeDto)
 {
     return(new WorkTime()
     {
         WorkStartTime = workTimeDto.WorkStartTime,
         WorkEndTime = workTimeDto.WorkEndTime,
         UserId = workTimeDto.UserId,
         TaskId = workTimeDto.TaskId
     });
 }
Example #3
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());
        }
Example #4
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)));
        }