public ActionResult SaveTastingNote(TastingNote tastingNoteSubmission) { if (tastingNoteSubmission == null || (tastingNoteSubmission.RecipeId == null && tastingNoteSubmission.BrewSessionId == null)) { return(this.Issue404()); } // Simple Validation if (tastingNoteSubmission.Rating < 1 || tastingNoteSubmission.Rating > 5) { return(this.Issue500()); } using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork()) { try { TastingNote tastingNote = null; if (tastingNoteSubmission.TastingNoteId > 0) { tastingNote = this.RecipeService.GetTastingNote(tastingNoteSubmission.TastingNoteId); } if (!this.RecipeService.AllowTastingNoteSubmission(tastingNote ?? tastingNoteSubmission)) { // Someone is trying to game the system. Ahh ahh ahh return(this.Issue500()); } tastingNote = Mapper.Map(tastingNoteSubmission, tastingNote); if (tastingNote.TastingNoteId > 0) { tastingNote.DateModified = DateTime.Now; } else { this.RecipeService.AddNewTastingNote(tastingNote); } unitOfWork.Commit(); // Set the User who left the notes tastingNote.User = this.UserService.GetUserById(this.ActiveUser.UserId); return(this.PartialView("~/Views/Recipe/_TastingNoteDetail.cshtml", tastingNote)); } catch (Exception ex) { this.LogHandledException(ex); unitOfWork.Rollback(); return(Content("-1")); } } }
/// <summary> /// Deletes a brewSessionTastingNote /// </summary> public void DeleteTastingNote(TastingNote tastingNote) { if (tastingNote == null) { throw new ArgumentNullException("tastingNote"); } tastingNote.DateModified = DateTime.Now; tastingNote.IsActive = false; }
/// <summary> /// Adds a new BrewSessionTastingNote /// </summary> public void AddNewTastingNote(TastingNote tastingNote) { if (tastingNote == null) { throw new ArgumentNullException("tastingNote"); } tastingNote.UserId = this.UserResolver.Resolve().UserId; tastingNote.DateCreated = DateTime.Now; tastingNote.IsActive = true; tastingNote.IsPublic = true; this.Repository.Add(tastingNote); }
/// <summary> /// Checks is the current users is allowed to perform a tasting note submission /// </summary> public bool AllowTastingNoteSubmission(TastingNote tastingNote) { // TODO: Allow invitation tasting note submissions // TODO: Allow invitation tasting note submissions // TODO: Allow invitation tasting note submissions // TODO: Allow invitation tasting note submissions var user = this.UserResolver.Resolve(); if (tastingNote.TastingNoteId > 0) { return(user.UserId == tastingNote.UserId); } else { return(this.Repository.GetSet <Recipe>() .Any(x => tastingNote.RecipeId != null && x.RecipeId == tastingNote.RecipeId) || this.Repository.GetSet <BrewSession>() .Any(x => tastingNote.BrewSessionId != null && x.BrewSessionId == tastingNote.BrewSessionId)); } }
public void DeleteTastingNote(TastingNote tastingNote) { _context.TastingNotes.Remove(tastingNote); }
public void UpdateTastingNote(TastingNote tastingNote) { _context.TastingNotes.Update(tastingNote); }
public void AddTastingNote(TastingNote tastingNote) { _context.TastingNotes.Add(tastingNote); }