示例#1
0
 public async Task <string> AddUser(TandemUser newUser)
 {
     _logger.LogInformation(traceSearchString + "about to add user to cosmos with emailAddress: " + newUser.EmailAddress);
     try
     {
         using (var context = new TandemUserContext(_dbOptions))
         {
             context.Database.EnsureCreated();
             newUser.UserId = Guid.NewGuid();
             newUser.id     = "TandemUser|" + newUser.UserId.ToString();
             context.Add(newUser);
             await context.SaveChangesAsync();
         }
     }
     catch (CosmosException cosmosException)
     {
         if (cosmosException.StatusCode == HttpStatusCode.Conflict)
         {
             // TODO: would make this a constant
             return("duplicateEmail");
         }
         throw;
     }
     _logger.LogInformation(traceSearchString + "add user to cosmos with Id: " + newUser?.UserId);
     return(newUser.UserId.ToString());
 }
示例#2
0
        public async Task <TandemUserDto> GetUserByEmailAddress(string emailAddress)
        {
            _logger.LogInformation(traceSearchString + "about to get user from cosmos with emailAddress: " + emailAddress);
            using (var context = new TandemUserContext(_dbOptions))
            {
                var tandemUser = await context.TandemUsers.Where(tu => tu.EmailAddress == emailAddress).FirstOrDefaultAsync();

                if (tandemUser?.id == null)
                {
                    _logger.LogInformation(traceSearchString + "did not find user from cosmos with emailAddress: " + emailAddress);
                    return(null);
                }
                _logger.LogInformation(traceSearchString + "retrieved user from cosmos with emailAddress: " + tandemUser.EmailAddress);
                var tandemUserDto = new TandemUserDto(tandemUser);
                return(tandemUserDto);
            }
        }