예제 #1
0
 private void AddVote(Picture photo, int value)
 {
     if (CheckVote(photo))
     {
         photo.Votes.Add(new Vote(User.Identity.GetUserId(), photo.Id, value));
         unitOfWork.Save();
     }
 }
 private void SaveEntities(Picture picture, IEnumerable<Tag> tags)
 {
     foreach (var tag in tags)
     {
         picture.Tags.Add(SearchTagInDb(tag));
     }
     unitOfWork.PictureRepository.Create(picture);
     unitOfWork.Save();
 }
예제 #3
0
 public ActionResult Upload(Picture picture, HttpPostedFileBase file, string tagsString)
 {
     if (ModelState.IsValid && file != null)
     {
         picture.FileName = file.FileName;
         SaveFile(file);
         SaveEntities(picture, ParseTags(tagsString));
     }
     return RedirectToAction("Index", "Home");
 }
예제 #4
0
 private void SaveEntities(Picture picture, IEnumerable<Tag> tags)
 {
     foreach (var tag in tags)
     {
         tag.Pictures.Add(picture);
         picture.Tags.Add(tag);
         SaveTag(tag);
     }
     unitOfWork.PictureRepository.Create(picture);
     unitOfWork.Save();
 }
 public ActionResult Upload(Picture picture, HttpPostedFileBase file, string tagsString)
 {
     if (ModelState.IsValid && file != null)
     {
         //TO DO: timestamp or hashcode
         picture.FileName = file.FileName;
         picture.UserId = User.Identity.GetUserId();
         SaveFile(file);
         SaveEntities(picture, ParseTags(tagsString));
     }
     return RedirectToAction("Index", "Home");
 }
예제 #6
0
 private int CountVotes(Picture photo)
 {
     return photo.Votes.Sum(vote => vote.Value);
 }
예제 #7
0
 private bool CheckVote(Picture photo)
 {
     return photo.UserId != User.Identity.GetUserId() && photo.Votes.All(vote => vote.UserId != User.Identity.GetUserId());
 }
예제 #8
0
 private void SaveEntities(Picture picture, IEnumerable<Tag> tags, HttpPostedFileBase file)
 {
     foreach (var tag in tags)
     {
         picture.Tags.Add(SearchTagInDb(tag));
     }
     unitOfWork.PictureRepository.Create(picture);
     unitOfWork.Save();
     SaveFile(file, picture.FileName);
     if (picture.Filter != FilterType.None)
         SaveFilteredImage(picture.FileName, picture.Filter);
 }
예제 #9
0
 public ActionResult Upload(Picture picture, HttpPostedFileBase file, string tagsString)
 {
     try
     {
         if (ModelState.IsValid && file != null && CheckExtension(Path.GetExtension(file.FileName).ToLower()))
         {
             picture.FileName = GenerateFileName(file);
             picture.UserId = User.Identity.GetUserId();
             SaveEntities(picture, ParseTags(tagsString), file);
         }
     }
     catch (Exception exception)
     {
         return RedirectToAction("Error", "Home", new { errorMessage = exception.Message });
     }
     return RedirectToAction("Show", "Photo", new { id = picture.Id });
 }