public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var email = (string)value; email = email.Trim().ToLower(); if (!cache.TryGetValue(email, out var avatar)) { var user = db.Users.FindOne(x => x.Email == email); if (user == null) { user = new UserModel(); user.Email = email; user.Avatar = GravatarUtils.FetchGravatarImage(email); db.Users.Upsert(user); } avatar = new BitmapImage(); avatar.BeginInit(); avatar.StreamSource = new MemoryStream(user.Avatar); avatar.EndInit(); } return(avatar); }
public async Task <ActionResult <UserProfile> > PostUserProfile(UserProfile userProfile) { userProfile.ImageUrl = GravatarUtils.GetGravatarUrl(userProfile.Email); userProfile.DateCreated = DateTime.Now; _context.UserProfile.Add(userProfile); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserProfile", new { id = userProfile.Id }, userProfile)); }
private void GetAvatarCommandAction() { ErrorText = string.Empty; if (!ValidEmailUtils.IsValidEmail(Email)) { ErrorText = "Please enter true email address!"; return; } Avatar = GravatarUtils.GetGravatar(Email); }