public async Task <Response <ProfileDto> > UpdateProfileAsync(string displayName, string email, string description, string googleId) { Response <ProfileDto> response = new(); Profile profile = _context.Profiles.FirstOrDefault(x => x.GoogleId == googleId); if (profile == null) { return(response); } profile.DisplayName = displayName; profile.Email = email; profile.Description = description; _context.Profiles.Update(profile); bool success = await _context.SaveChangesAsync() > 0; if (success) { response.Success = true; response.Data = _mapper.Map <ProfileDto>(profile); UpdateProfileEvent(response.Data); } return(response); }
public async Task <bool> Consume(string message) { UserEvent userEvent = JsonConvert.DeserializeObject <UserEvent>(message); if (userEvent == null) { return(false); } Profile profile = new Profile { Id = userEvent.Id, Avatar = userEvent.Avatar, DisplayName = userEvent.DisplayName, DateOfCreation = userEvent.DateOfCreation, Email = userEvent.Email, GoogleId = userEvent.GoogleId }; await _context.Profiles.AddAsync(profile); bool success = await _context.SaveChangesAsync() > 0; if (!success) { return(false); } ProfileDto profileDto = _mapper.Map <ProfileDto>(profile); CreateProfileEvent(profileDto); return(true); }
/// <summary> /// Seed application context. /// </summary> /// <param name="context">Application context.</param> public static async Task SeedAsync(IProfileContext context) { if (!context.Profiles.Any()) { await context.Profiles.AddRangeAsync(GetPreconfiguredProfileModels()); await context.SaveChangesAsync(new CancellationToken()); } }
/// <inheritdoc/> public async Task <(Guid id, bool success)> RegisterNewProfileAsync(ProfileDTO profileDTO) { var profile = _mapper.Map <ProfileDTO, ProfileModel>(profileDTO); var profileFound = await _profileContext.Profiles.FirstOrDefaultAsync(p => p.Passport == profileDTO.Passport); if (profileFound != null) { _logger.Error(ProfileConstants.PROFILE_ALREADY_EXIST); return(Guid.Empty, false); } await _profileContext.Profiles.AddAsync(profile); await _profileContext.SaveChangesAsync(new CancellationToken()); var id = profile.Id; return(id, true); }