Esempio n. 1
0
        public bool CanUserAddAlbum(string userId)
        {
            FreeUserProfile userProfile     = _unitOfWork.UserProfiles.SingleOrDefault(x => x.UserIdentityId == userId) as FreeUserProfile;
            int             freeAlbumsLimit = Convert.ToInt32(WebConfigurationManager.AppSettings["freeAlbumsLimit"]);

            return((userProfile == null) || userProfile.FreeAlbumsCreated < freeAlbumsLimit);
        }
Esempio n. 2
0
        public void CreateUserProfile(string userId, string role)
        {
            UserProfile userProfile;

            switch (role)
            {
            case "FreeUser":
                userProfile = new FreeUserProfile()
                {
                    UserIdentityId = userId
                };
                break;

            case "PaidUser":
                userProfile = new PaidUserProfile()
                {
                    UserIdentityId = userId
                };
                break;

            default:
                throw new ArgumentException("The role for User Profile was not provided.");
            }

            _context.UserProfiles.Add(userProfile);
        }
Esempio n. 3
0
        public void AddAlbum(Album album, int photoId)
        {
            Photo photo = _unitOfWork.Photos.Get(photoId);

            album.MainPhoto = photo;
            _unitOfWork.Albums.Add(album);

            UserProfile     userProfile     = _unitOfWork.UserProfiles.SingleOrDefault(x => x.UserIdentityId == album.UserId);
            FreeUserProfile freeUserProfile = userProfile as FreeUserProfile;

            if (freeUserProfile != null)
            {
                freeUserProfile.FreeAlbumsCreated++;
            }
            _unitOfWork.Complete();
        }
Esempio n. 4
0
        public void AddPhoto(Photo model, Stream inputStream)
        {
            using (var img = Image.FromStream(inputStream))
            {
                PhotoBytesContent photoBytesContent = new PhotoBytesContent();

                Bitmap bitmapThumb = ResizeImage(img, 200, 200);
                using (Image newImg = bitmapThumb)
                {
                    photoBytesContent.ThumbPhoto = ImageToByteArray(newImg);
                }

                Bitmap bitmapOriginal = ResizeImage(img, img.Size.Width, img.Size.Height);
                using (Image newImg = bitmapOriginal)
                {
                    photoBytesContent.OriginalPhoto = ImageToByteArray(newImg);
                }

                Bitmap bitmapMedium = ResizeImage(img, 800, 800);
                using (Image newImg = bitmapMedium)
                {
                    photoBytesContent.MediumPhoto = ImageToByteArray(newImg);
                }

                model.PhotoBytesContent = photoBytesContent;

                // Save records to database
                _unitOfWork.Photos.Add(model);
                UserProfile     userProfile     = _unitOfWork.UserProfiles.SingleOrDefault(x => x.UserIdentityId == model.UserId);
                FreeUserProfile freeUserProfile = userProfile as FreeUserProfile;
                if (freeUserProfile != null)
                {
                    freeUserProfile.FreePhotosUploaded++;
                }

                _unitOfWork.Complete();
            }
        }