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(); }
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"); }
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"); }
private int CountVotes(Picture photo) { return photo.Votes.Sum(vote => vote.Value); }
private bool CheckVote(Picture photo) { return photo.UserId != User.Identity.GetUserId() && photo.Votes.All(vote => vote.UserId != User.Identity.GetUserId()); }
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); }
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 }); }