public async Task <UserModel> UpdateAsync(string userId, UserModel input) { input.CheckUser(); if (userId != input.Id) { throw new ArgumentException("Corrupted data."); } TUser dbUserAuth = await _userAuth.GetCurrentUserAsync("updated user"); TUser dbUser = await _context.TUser.FirstOrDefaultAsync(x => x.UsrId.Equals(userId)); if (dbUser == null || dbUser.UsrId != dbUserAuth.UsrId) { throw new ArgumentException("Corrupted data."); } dbUser = input.ToUpdate(dbUser); await _context.SaveChangesAsync(); var result = dbUser.ToUserModel(); return(result); }
public async Task <UserModel> ReadAsync(string userId) { TUser dbUser = await _context.TUser.FirstOrDefaultAsync(x => x.UsrId.Equals(userId)); var result = dbUser.ToUserModel(); return(result); }
public async Task <UserModel> CreateAsync(UserModel input) { input.CheckUser(); TUser dbUser = input.ToCreate(); await _context.TUser.AddAsync(dbUser); await _context.SaveChangesAsync(); var result = dbUser.ToUserModel(); return(result); }