예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
 private void GetAvatarCommandAction()
 {
     ErrorText = string.Empty;
     if (!ValidEmailUtils.IsValidEmail(Email))
     {
         ErrorText = "Please enter true email address!";
         return;
     }
     Avatar = GravatarUtils.GetGravatar(Email);
 }