Exemplo n.º 1
0
 public ActionResult Create(PhotoAddInfoViewModel photoAddInfoViewModel)
 {
     Int32 photoId;
     var file = HttpContext.Request.Files[0];
     if (file != null)
     {
         photoAddInfoViewModel.OriginalPhoto = file;
         photoAddInfoViewModel.Login = User.Identity.Name;
         var tags =
             new List<String>(photoAddInfoViewModel.TagsString.ToLower()
                                                   .Split(new string[] {","},
                                                          StringSplitOptions.RemoveEmptyEntries));
         photoAddInfoViewModel.TagAddViewModels = new Collection<TagAddViewModel>();
         foreach (var tag in tags)
         {
             photoAddInfoViewModel.TagAddViewModels.Add(new TagAddViewModel(tag));
         }
         photoId = photoService.CreatePhoto(photoAddInfoViewModel);
     }
     else
     {
         return View();
     }
     return RedirectToAction("Details", new {photoId = photoId});
 }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 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;
 }