コード例 #1
0
        public void RemoveIncludingBytesContent(Photo photo)
        {
            Photo realPhotoEntity = _context.Photos.Single(x => x.PhotoId == photo.PhotoId);

            PhotoBytesContent photoBytesContent = realPhotoEntity.PhotoBytesContent;

            _context.PhotoBytesContents.Remove(photoBytesContent);


            List <Vote> votes = realPhotoEntity.Votes;

            _context.Votes.RemoveRange(votes);

            _context.Photos.Remove(realPhotoEntity);
        }
コード例 #2
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();
            }
        }