public async Task <UserContentDataModel> AddUserContentAsync(LoginResultDataModel loginInfo, UserContentDataModel model) { if (!LoginInformationComplete(loginInfo)) { return(null); } bool unique; do { unique = true; if (dbContext.UserContent.Where(e => e.User.UserId == loginInfo.UserId).Where(e => e.Id == model.Id).Any()) { model.Id = Guid.NewGuid().ToString("N"); unique = false; } } while (!unique); dbContext.UserContent.Add(new UserContentDatabaseModel { Id = model.Id, User = dbContext.LoginCredentials.Where(e => e.UserId == loginInfo.UserId).First(), AccountNameHash = model.AccountNameHash, EmailHash = model.EmailHash, UsernameHash = model.UsernameHash, WebsiteHash = model.WebsiteHash, PasswordHash = model.PasswordHash, NotesHash = model.NotesHash, }); await dbContext.SaveChangesAsync(); return(model); }
public async Task <UserContentDataModel> UpdateUserContentAsync(LoginResultDataModel loginInfo, UserContentDataModel model) { if (!LoginInformationComplete(loginInfo)) { return(null); } var table = await dbContext.UserContent.Where(e => e.User.UserId == loginInfo.UserId).Where(e => e.Id == model.Id).ToListAsync(); if (table == null || table.Count != 1) { return(null); } table.First().AccountNameHash = model.AccountNameHash; table.First().EmailHash = model.EmailHash; table.First().UsernameHash = model.UsernameHash; table.First().WebsiteHash = model.WebsiteHash; table.First().PasswordHash = model.PasswordHash; table.First().NotesHash = model.NotesHash; await dbContext.SaveChangesAsync(); return(model); }