public IActionResult CreateTask([FromBody] NewTaskForm taskForm) { // Assign the data from body to variables var aircraftId = taskForm.AircraftId; var title = taskForm.Title; var status = taskForm.Staus; var description = taskForm.Description; // Create a new response body var res = new BaseResponse(); try { // Send the varisbles to the Task Manager to create a new Task var createdTask = manager.CreateTask(aircraftId, title, status, description); if (createdTask) { // Respond with a 200 + the task body res.Code = 200; res.HasBeenSuccessful = true; return(Ok(res)); } // Repond with 401, something went wrong res.Code = 401; res.HasBeenSuccessful = false; return(Ok(res)); } catch (Exception e) { // Repond with 501, something went wrong internally res.Code = 501; res.HasBeenSuccessful = false; return(Ok(res)); } }
public async Task <ValidationResult> AddTaskToDatabase(AddNewTaskViewModel vm) { var validationResult = NewTaskForm.IsValid(vm); if (validationResult.IsValid) { int?storyPoints = null; try { if (vm.TaskNameTextBox.Contains(",")) { var substring = vm.TaskNameTextBox.Substring(vm.TaskNameTextBox.IndexOf(",") + 1); storyPoints = Convert.ToInt32(substring.Replace(" ", string.Empty)); vm.TaskNameTextBox = vm.TaskNameTextBox.Substring(0, vm.TaskNameTextBox.IndexOf(",")); } } catch (FormatException) { validationResult.Message = "SP podajemy po przecinku jako liczba!"; validationResult.IsValid = false; return(validationResult); } var newTask = new TaskManager.Models.Task { Name = vm.TaskNameTextBox, Description = vm.DescriptionTextBox, Priority = vm.Priority, ProjectId = Repository.Instance.Projects.Single(p => p.Name == vm.SelectedProjectsList).Id, StoryPoints = storyPoints }; var httpDataService = new HttpDataService(); var taskFromResponse = await httpDataService.Post(newTask); await Repository.Instance.FetchUpdates(); validationResult.Message = "Task dodano pomyślnie!"; } return(validationResult); }