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")); }
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); }
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); }
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")); }