public async Task <ActionResult> Add([FromBody] CustardQuotesModel newQuote) { await _context.CustardQuotes.AddAsync(newQuote); await _context.SaveChangesAsync(); //TODO: Check if change is allowed return(Ok()); }
private async Task AddUserToGroup(string userId, int groupId) { UserGroupsModel entry = new UserGroupsModel { UserId = userId, GroupId = groupId }; _context.UserGroups.Add(entry); try { await _context.SaveChangesAsync(); } catch (DbUpdateException e) { Console.WriteLine("Already in the DB"); } }
private async Task <UsersModel> CreateUser(UsersModel usersModel) { usersModel.Id = Guid.NewGuid().ToString(); _context.Users.Add(usersModel); try { await _context.SaveChangesAsync(); } catch (DbUpdateException e) { if (UsersModelExists(usersModel.Id)) { return(await CreateUser(usersModel)); } else { throw e; } } return(usersModel); }