public async Task <IActionResult> UpdateTaskListAsync(TaskList taskList, [FromServices] IMongoCollection <TaskList> mongoCollection) { if (taskList == null || !taskList.AreValuesCorrect()) { return(new JsonResult(new { Type = "Error", Details = "TaskList is null or it's properties are empty!" })); } TaskList currentValue = await mongoCollection.FirstOrDefaultAsync(x => x.ID == taskList.ID); if (currentValue == null) { return(new JsonResult(new { Type = "Error", Details = "Sended TaskList to update has altered ID! Unable to update value!" })); } UpdateResult result = await mongoCollection.UpdateOneAsync(x => x.ID == taskList.ID, Extensions.GenerateUpdateDefinition(currentValue, taskList)); if (result.IsAcknowledged) { return(new JsonResult(new { Type = "Success", Details = "" })); } else { return(new JsonResult(new { Type = "Error", Details = "Update somehow failed!" })); } }
public async Task <IActionResult> UpdateTaskListAsync(TaskList taskList, [FromServices] IMongoCollection <TaskList> mongoCollection) { if (taskList == null || !taskList.AreValuesCorrect()) { return(this.Error(HttpStatusCode.UnprocessableEntity, "TaskList is null or it's properties are empty!")); } TaskList currentValue = await mongoCollection.FirstOrDefaultAsync(x => x.ID == taskList.ID); if (currentValue == null) { return(this.Error(HttpStatusCode.BadRequest, "Sended TaskList to update has altered Id! Unable to update value!")); } UpdateResult result = await mongoCollection.UpdateOneAsync(x => x.ID == taskList.ID, Extensions.GenerateUpdateDefinition(currentValue, taskList)); if (result.IsAcknowledged) { return(Ok()); } return(this.Error(HttpStatusCode.InternalServerError, "Update somehow failed!")); }
public async Task <IActionResult> AddTaskListToEventAsync(Dictionary <string, string> data, [FromServices] IMongoCollection <TaskList> mongoCollection, [FromServices] IMongoCollection <CalendarEvent> eventsMongoCollection) { Guid eventID = Guid.Parse(data["eventID"]); TaskList value = JsonConvert.DeserializeObject <TaskList> (data["taskList"]); if (eventID == Guid.Empty) { return(new JsonResult(new { Type = "Error", Details = "EventID is empty!" })); } if (value == null || !value.AreValuesCorrect()) { return(new JsonResult(new { Type = "Error", Details = "Sended taskList is null or has empty properties!" })); } CalendarEvent calendarEvent = await eventsMongoCollection.FirstOrDefaultAsync(x => x.ID == eventID); if (calendarEvent == null) { return(new JsonResult(new { Type = "Error", Details = "There's no Calendar Event with given eventID!" })); } if (calendarEvent.TaskListID != Guid.Empty) { return(new JsonResult(new { Type = "Error", Details = "Given Event already has the TaskList!" })); } value.ID = Guid.NewGuid(); await mongoCollection.InsertOneAsync(value); CalendarEvent newValue = calendarEvent; newValue.TaskListID = value.ID; await eventsMongoCollection.UpdateOneAsync(x => x.ID == eventID, Extensions.GenerateUpdateDefinition(calendarEvent, newValue)); return(new JsonResult(new { Type = "Success", Details = value.ID })); }
public async Task <IActionResult> AddTaskListAsync(TaskList taskList, [FromServices] IMongoCollection <TaskList> mongoCollection) { if (taskList == null || !taskList.AreValuesCorrect()) { return(new JsonResult(new { Type = "Error", Details = "TaskList is null or it's properties are empty!" })); } taskList.ID = Guid.NewGuid(); await mongoCollection.InsertOneAsync(taskList); return(new JsonResult(new { Type = "Success", Details = taskList.ID })); }
public async Task <IActionResult> AddTaskListAsync(TaskList taskList, [FromServices] IMongoCollection <TaskList> mongoCollection, [FromServices] IMongoCollection <CalendarEvent> eventCollection) { if (taskList == null || !taskList.AreValuesCorrect()) { return(this.Error(HttpStatusCode.UnprocessableEntity, "TaskList is null or it's properties are empty!")); } taskList.ID = Guid.NewGuid(); await mongoCollection.InsertOneAsync(taskList); return(this.Success(taskList.ID)); }