public IActionResult Create([FromBody] ClientTaskViewModel clientTaskViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    int id          = clientTaskService.Create(clientTaskViewModel);
                    var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
                    var locationUri = baseUrl + "/" + ApiRoutes.ClientTask.GetTaskById.Replace("{taskId}", id.ToString()).Replace("{clientId}", clientTaskViewModel.ClientId.ToString());
                    return(Created(locationUri, new ClientTaskViewModel {
                        Id = id,
                        TaskName = clientTaskViewModel.TaskName,
                        Description = clientTaskViewModel.Description,
                        ClientAddress = clientTaskViewModel.ClientAddress,
                        ClientId = clientTaskViewModel.ClientId,
                        StartTime = clientTaskViewModel.StartTime,
                        EndTime = clientTaskViewModel.EndTime
                    }));
                }

                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(BadRequest("Insert valid data"));
        }
예제 #2
0
        public int Create(ClientTaskViewModel clientTaskViewModel)
        {
            ClientTaskDTO clientTaskDTO = new ClientTaskDTO();

            clientTaskDTO.TaskName      = clientTaskViewModel.TaskName;
            clientTaskDTO.Description   = clientTaskViewModel.Description;
            clientTaskDTO.ClientAddress = clientTaskViewModel.ClientAddress;
            clientTaskDTO.ClientId      = clientTaskViewModel.ClientId;
            clientTaskDTO.StartTime     = clientTaskViewModel.StartTime;
            clientTaskDTO.EndTime       = clientTaskViewModel.EndTime;

            int id = clientTaskRepository.Create(clientTaskDTO);

            return(id);
        }
예제 #3
0
        public bool Update(ClientTaskViewModel clientTaskViewModel)
        {
            ClientTaskDTO clientTaskDTO = new ClientTaskDTO();

            clientTaskDTO.Id            = clientTaskViewModel.Id;
            clientTaskDTO.TaskName      = clientTaskViewModel.TaskName;
            clientTaskDTO.Description   = clientTaskViewModel.Description;
            clientTaskDTO.ClientAddress = clientTaskViewModel.ClientAddress;
            clientTaskDTO.ClientId      = clientTaskViewModel.ClientId;
            clientTaskDTO.StartTime     = clientTaskViewModel.StartTime;
            clientTaskDTO.EndTime       = clientTaskViewModel.EndTime;

            bool status = clientTaskRepository.Update(clientTaskDTO);

            return(status);
        }
예제 #4
0
        public List <ClientTaskViewModel> GetTasksByClientId(int id)
        {
            List <ClientTaskDTO> clientTaskDTOs = clientTaskRepository.GetTasksByClientId(id);

            List <ClientTaskViewModel> clientTaskViewModels = new List <ClientTaskViewModel>();

            foreach (ClientTaskDTO clientTaskDTO in clientTaskDTOs)
            {
                ClientTaskViewModel clientTaskViewModel = new ClientTaskViewModel();
                clientTaskViewModel.Id            = clientTaskDTO.Id;
                clientTaskViewModel.TaskName      = clientTaskDTO.TaskName;
                clientTaskViewModel.Description   = clientTaskDTO.Description;
                clientTaskViewModel.ClientAddress = clientTaskDTO.ClientAddress;
                clientTaskViewModel.StartTime     = clientTaskDTO.StartTime;
                clientTaskViewModel.EndTime       = clientTaskDTO.EndTime;
                clientTaskViewModel.ClientId      = clientTaskDTO.ClientId;

                clientTaskViewModels.Add(clientTaskViewModel);
            }
            return(clientTaskViewModels);
        }
        public IActionResult Update([FromBody] ClientTaskViewModel clientTaskViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var status = clientTaskService.Update(clientTaskViewModel);
                    if (!status)
                    {
                        return(BadRequest("Task is not updated"));
                    }
                    else
                    {
                        return(NoContent());
                    }
                }

                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(BadRequest("Insert valid data"));
        }