public async Task <ActionResult <UserGroupShoppingListResult> > CreateAssignment([FromBody] UserGroupShoppingList assignment) { var result = new UserGroupShoppingListResult(); try { result.IsSuccessful = true; var created = await _userGroupShoppingLists.CreateAsync(assignment); result.ResultData.Add(created); } catch (ItemAlreadyExistsException e) { result.IsSuccessful = false; result.ErrorMessages.Add(e.Message); return(Conflict(result)); } catch (PersistencyException e) { result.IsSuccessful = false; result.ErrorMessages.Add(e.Message); return(Conflict(result)); } return(Ok(result)); }
public async Task <ActionResult <UserGroupShoppingListResult> > DeleteAssignment(string groupId, string listId) { var result = new UserGroupShoppingListResult(); var assignment = new UserGroupShoppingList() { UserGroupId = groupId, ShoppingListId = listId }; try { bool deleteResult = await _userGroupShoppingLists.DeleteAsync(assignment); if (!deleteResult) { result.IsSuccessful = false; result.ErrorMessages.Add($"Could not delete assignment Group:'{groupId}'<-->List:'{listId}'"); return(UnprocessableEntity(result)); } result.IsSuccessful = true; } catch (ItemNotFoundException e) { result.IsSuccessful = false; result.ErrorMessages.Add(e.Message); return(NotFound(result)); } catch (PersistencyException e) { result.IsSuccessful = false; result.ErrorMessages.Add(e.Message); return(NotFound(result)); } return(Ok(result)); }