/// <summary> /// A Lambda function that adds a task. /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <APIGatewayProxyResponse> AddTaskAsync(APIGatewayProxyRequest request, ILambdaContext context) { context.Logger.LogLine($"Saving task"); var newTask = JsonConvert.DeserializeObject <NewTask>(request?.Body); TransTask addTask = new TransTask { name = newTask.name, book = newTask.book, description = newTask.description, passageSet = newTask.passageSet, taskID = newTask.taskID }; await TaskService.AddTransTask(addTask); var response = new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.OK, Body = addTask._id.ToString(), Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } } }; return(response); }
public async Task <string> AddTransTask(TransTask item) { try { await _tasks.InsertOneAsync(item); return(item._id.ToString()); } catch (Exception ex) { // log or manage the exception throw ex; } }
public async Task <TransTask> Create(NewTask newTask) { TransTask addTask = new TransTask { name = newTask.name, book = newTask.book, description = newTask.description, passageSet = newTask.passageSet, taskID = newTask.taskID }; var id = await _taskService.AddTransTask(addTask); return(await _taskService.GetTransTaskById(id)); }
public async Task <APIGatewayProxyResponse> UpdateTaskAsync(APIGatewayProxyRequest request, ILambdaContext context) { string taskId = GetTaskIdParam(request); if (string.IsNullOrEmpty(taskId)) { return(new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.BadRequest, Body = $"Missing required parameter {ID_QUERY_STRING_NAME}" }); } //get the requested task var task = await TaskService.GetTransTaskById(taskId); context.Logger.LogLine($"Found task: {task != null}"); if (task == null) { return(new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.NotFound }); } var newTask = JsonConvert.DeserializeObject <NewTask>(request?.Body); TransTask updTask = new TransTask { _id = task._id, name = newTask.name, book = newTask.book, description = newTask.description, passageSet = newTask.passageSet, taskID = newTask.taskID }; await TaskService.UpdateTransTask(taskId, updTask); var response = new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.OK, Body = updTask._id.ToString(), Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } } }; return(response); }
public async Task <bool> UpdateTransTask(string id, TransTask item) { try { ReplaceOneResult actionResult = await _tasks .ReplaceOneAsync(n => n.taskID.Equals(id) || n._id == GetInternalId(id) , item , new UpdateOptions { IsUpsert = true }); return(actionResult.IsAcknowledged && actionResult.ModifiedCount > 0); } catch (Exception ex) { // log or manage the exception throw ex; } }