Пример #1
0
 private void SetTags(string tagString, Photo photo)
 {
     IEnumerable<string> tags = TagService.SplitTags(tagString).Distinct();
     if (photo.Tags != null)
     {
         photo.Tags.Clear();
     }
     else
     {
         photo.Tags = new List<Tag>();
     }
     foreach (var tag in tags)
     {
         var tmp = unitOfWork.TagRepository.GetTagByName(tag.Trim());
         if (tmp == null)
         {
             tmp = new Tag
             {
                 Name = tag.Trim()
             };
             unitOfWork.TagRepository.Insert(tmp);
             unitOfWork.Save();
         }
         photo.Tags.Add(tmp);
     }
 }
Пример #2
0
 private void UploadPhoto(UploadModel model)
 {
     var photo = new Photo
     {
         Description = model.Description,
         Filename = PhotoService.SavePhoto(model.Photo),
         UserID = WebSecurity.CurrentUserId
     };
     if (model.Tags != null)
     {
         SetTags(model.Tags, photo);
     }
     unitOfWork.PhotoRepository.Insert(photo);
     unitOfWork.Save();
 }
Пример #3
0
 private void DeletePhoto(int id, Photo photoToDelete)
 {
     unitOfWork.PhotoRepository.Delete(id);
     //unitOfWork.RatingRepository.DeletePhotoRating(id);
     unitOfWork.Save();
     string[] photos = System.IO.Directory.GetFiles(Server
         .MapPath(Settings.Default.UserUploads), "*" + photoToDelete.Filename);
     foreach (var photo in photos)
     {
         if (System.IO.File.Exists(photo))
         {
             System.IO.File.Delete(photo);
         }
     }
 }