Exemplo n.º 1
0
 public async Task PostBanner(SetImage request)
 {
     UserInfo user = await GetUserInfoAsync();
     HttpStatusCode result = await UserOperations.SetBannerImage(
         DbContext, user, request);
     result.ThrowHttpResponseExceptionIfNotSuccessful();
 }
Exemplo n.º 2
0
        public static async Task<HttpStatusCode> SetAvatarImage(
            ApplicationDbContext dbContext,
            UserInfo user,
            SetImage request)
        {
            UserMedia media = await dbContext.UserMedias
                .SingleOrDefaultAsync(um => um.UserMediaId == request.MediaId);
            if (media == null)
            {
                return HttpStatusCode.BadRequest;
            }

            if (!media.MediaAlbumId.HasValue)
            {

                if (user.AvatarsMediaAlbumId.HasValue)
                {
                    media.MediaAlbumId = user.AvatarsMediaAlbumId;
                }
                else
                {
                    var avatarsAlbum = new MediaAlbum
                    {
                        User = user,
                        Title = "Avatar Images",
                        Description = "Images used as my avatar"
                    };
                    user.AvatarsAlbum = avatarsAlbum;
                    media.MediaAlbum = avatarsAlbum;
                }
            }

            user.Avatar = media;
            await dbContext.SaveChangesAsync();

            return HttpStatusCode.OK;
        }