Exemple #1
0
        public IActionResult AddPhoto(PhotoModel model, int?albumId)
        {
            if (ModelState.IsValid)
            {
                var photo = new Domain.Photo()
                {
                    AlbumId  = albumId,
                    PostId   = null,
                    MIMEType = model.Binar.ContentType
                };
                using (var memoryStream = new MemoryStream())
                {
                    model.Binar.CopyTo(memoryStream);
                    photo.Binary = memoryStream.ToArray();
                }
                photoService.AddPhoto(photo);

                return(RedirectToAction("Album", "Profile", new { albumId = model.AlbumId }));
            }
            if (albumId == null)
            {
                return(NotFound());
            }
            AlbumViewerModel albumViewerModel = new AlbumViewerModel()
            {
                PhotoModel   = model,
                HasThisAlbum = albumService.HasThisAlbum(albumId.Value),
                Id           = albumId.Value,
                Name         = albumService.GetAlbum(albumId.Value).Name
            };

            return(View("Album", albumViewerModel));
        }
Exemple #2
0
        public void AddPhoto(Domain.Photo photo)
        {
            var isBanned = unitOfWork.Users.Query.FirstOrDefault(e => e.Id == currentUser.Id)?.IsBanned ?? false;

            if (isBanned)
            {
                return;
            }

            unitOfWork.Photos.Add(photo);
            if (photo.PostId.HasValue)
            {
                var post = unitOfWork.Posts.Query
                           .Include(e => e.Photo)
                           .FirstOrDefault(e => e.Id == photo.PostId);

                post.Photo = photo;
                unitOfWork.Posts.Update(post);
            }
            else
            {
                photo.Position = unitOfWork.Photos.Query
                                 .Where(e => e.AlbumId == photo.AlbumId)
                                 .Count() + 1;
            }
            unitOfWork.SaveChanges();
        }
Exemple #3
0
 public PhotoModel Build(Domain.Photo photo)
 {
     return(new PhotoModel
     {
         Title = photo.Title,
         ThumbnailUrl = photo.ThumbnailUrl,
         Url = photo.Url
     });
 }
Exemple #4
0
        public async Task <CreatePhotoResponse> CreatePhoto(CreatePhotoRequest request, CancellationToken cancellationToken)
        {
            if (request.Photo.Length > 5242880)
            {
                throw new OverflowMaxSizePhotoException();
            }

            var photo = new Domain.Photo()
            {
                KodBase64 = Convert.ToBase64String(request.Photo, 0, request.Photo.Length)
            };
            await _repository.Save(photo, cancellationToken);

            return(_mapper.Map <CreatePhotoResponse>(photo));
        }
Exemple #5
0
        public static PhotoBlock GetVideoSize(Domain.Photo photo, VideoSize size)
        {
            switch (size)
            {
            default:
            case VideoSize.Small:
                return(photo.Small);

            case VideoSize.Medium:
                return(photo.Medium);

            case VideoSize.Standard:
                return(photo.Standard);

            case VideoSize.Large:
                return(photo.Large);
            }
        }
Exemple #6
0
        public override bool ApplyChanges()
        {
            // Make sure that all is set up
            EnsureChildControls();

            // Update the web part
            VisualEmbed webPart = (VisualEmbed)WebPartToEdit;

            if (webPart != null)
            {
                // Get the token for the photo first
                if (Videos != null)
                {
                    IPhotoService photoService = new PhotoService(Utilities.ApiProvider);
                    Domain.Photo  photo        = photoService.Get(Convert.ToInt32(Videos.SelectedValue), false);

                    webPart.PhotoId    = Videos.SelectedValue;
                    webPart.PhotoToken = photo.Token;
                }
            }

            return(true);
        }