Exemple #1
0
        public Int32 CreatePhoto(PhotoAddInfoViewModel photoCard)
        {
            var imageData = photoUploadService.UploadPhoto(photoCard.OriginalPhoto.FileName, photoCard.OriginalPhoto.InputStream);
            var photo = new Photo
            {
                Description = photoCard.Description,
                OriginalPhoto = imageData

            };
            var user = userProfileRepository.GetByLogin(photoCard.Login);
            if (user != null)
            {
                photo.Owner = user;
            }
            else
            {
                throw new Exception("Шеф усё пропало");
            }

            photo.Tags = new Collection<Tag>();
            foreach (var tagsViewModel in photoCard.TagAddViewModels)
            {
                photo.Tags.Add(tagService.CheckTag(tagsViewModel.Name));
            }
            return photoRepository.Create(photo).Id;
        }
 public PhotoSlideShowViewModel(Photo photo)
 {
     PhotoUrl = photo.ModifiedPhoto ?? photo.OriginalPhoto.Url;
     PhotoId = photo.Id;
     OwnerLogin = photo.Owner.UserName;
     CommonRaiting = photo.CommonRaiting;
 }
 public PhotoCommonInfoViewModel(Photo photo)
 {
     PhotoId = photo.Id;
     OwnerOfPhotoName = photo.Owner.UserName;
     PhotoUrl = photo.ModifiedPhoto ?? photo.OriginalPhoto.Url;
     AmountOfLikes = photo.AmountOfLikes;
     AmountOfDislikes = photo.AmountOfDislikes;
     CommonRaiting = photo.CommonRaiting;
 }
 internal Photo ConvertPhotoAddInfoModelToPhoto(PhotoAddInfoViewModel addInfoViewModel)
 {
     var photo = new Photo
         {
             Description = addInfoViewModel.Description,
     //                    OriginalPhoto = addInfoViewModel.OriginalPhoto,
     //                    ModifiedPhoto = addInfoViewModel.ModifiedPhoto,
             Tags = ConvertListTagSimpleViewModelToListTag(addInfoViewModel.TagAddViewModels).ToList()
         };
     return photo;
 }
 public PhotoCommonInfoViewModel(Photo photo, String currentUserName, Boolean isLiked, Boolean isDisliked)
 {
     PhotoId = photo.Id;
     OwnerOfPhotoName = photo.Owner.UserName;
     CurrentUserName = currentUserName;
     PhotoUrl = photo.ModifiedPhoto ?? photo.OriginalPhoto.Url;
     AmountOfLikes = photo.AmountOfLikes;
     AmountOfDislikes = photo.AmountOfDislikes;
     CommonRaiting = photo.CommonRaiting;
     IsLiked = isLiked;
     IsDisliked = isDisliked;
 }
 internal PhotoUpdateInfoViewModel ConvertPhotoToPhotoUpdateInfoViewModel(Photo photo)
 {
     var photoUpdateInfoViewModel = new PhotoUpdateInfoViewModel
         {
             Id = photo.Id,
             Description = photo.Description,
             TagsViewModels = ConvertListTagToListTagSimpleViewModel(photo.Tags),
             OriginalPhoto = photo.OriginalPhoto,
             ModifiedPhoto = photo.ModifiedPhoto
         };
     photoUpdateInfoViewModel.TagsString = "";
     foreach (var tagViewModel in photoUpdateInfoViewModel.TagsViewModels)
     {
         photoUpdateInfoViewModel.TagsString = String.Format("{0},{1}", photoUpdateInfoViewModel.TagsString, tagViewModel.Name);
     }
     return photoUpdateInfoViewModel;
 }
 public PhotoDetailedInfoViewModel(Photo photo, String currentUserLogin, Boolean isLiked, Boolean isDisliked)
 {
     PhotoId = photo.Id;
     PhotoUrl = photo.ModifiedPhoto ?? photo.OriginalPhoto.Url;
     Description = photo.Description;
     AmountOfLikes = photo.AmountOfLikes;
     AmountOfDislikes = photo.AmountOfDislikes;
     CommonRaiting = photo.CommonRaiting;
     IsLiked = isLiked;
     IsDisliked = isDisliked;
     OwnerLogin = photo.Owner.UserName;
     CurrentUserLogin = currentUserLogin;
     var tags = photo.Tags;
     TagSimpleViewModels = new Collection<TagSimpleViewModel>();
     foreach (var tag in tags)
     {
         TagSimpleViewModels.Add(new TagSimpleViewModel(tag));
     }
 }
Exemple #8
0
 private void CompareTags(Photo photo, IEnumerable<TagSimpleViewModel> newTagSimpleViewModels)
 {
     var newTags = new List<Tag>();
     foreach (var newTagSimpleViewModel in newTagSimpleViewModels)
     {
         var currentTag = tagRepository.GetByName(newTagSimpleViewModel.Name);
         if (currentTag == null)
         {
             tagRepository.Create(new Tag()
                 {
                     Name = newTagSimpleViewModel.Name,
                     Count = 1
                 });
             photo.Tags.Add(tagRepository.GetByName(newTagSimpleViewModel.Name));
             newTags.Add(tagRepository.GetByName(newTagSimpleViewModel.Name));
         }
         else if (!photo.Tags.Contains(currentTag))
         {
             currentTag.Count++;
             photo.Tags.Add(currentTag);
             newTags.Add(currentTag);
         }
         else
         {
             newTags.Add(currentTag);
         }
     }
     var excepts = photo.Tags.Except(newTags.AsEnumerable()).ToList();
     foreach (var except in excepts)
     {
         if (tagRepository.GetByName(except.Name).Count == 1)
         {
             tagRepository.Remove(except);
         }
         else
         {
             tagRepository.GetByName(except.Name).Count--;
             tagRepository.Update(except);
         }
     }
     photo.Tags.Clear();
     foreach (var newTag in newTags)
     {
         photo.Tags.Add(newTag);
     }
     photoRepository.Update(photo);
 }