Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show feedback user email to author #346

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Data/DataModel/Feedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,48 @@ namespace ServerCore.DataModel
{
public class Feedback
{
public Feedback()
{
Fun = AvgRating;
Difficulty = AvgRating;
}

public const int MinRating = 1;
public const int AvgRating = 5;
public const int MaxRating = 10;

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }

[Required]
public virtual Puzzle Puzzle { get; set; }

/// <summary>
/// The user who submitted the feedback>
/// </summary>
[Required]
public virtual PuzzleUser Submitter {get; set;}

/// <summary>
/// The time the feedback was submitted.
/// </summary>
public DateTime SubmissionTime { get; set; }

/// <summary>
/// The feedback text submitted by the user.
/// </summary>
public string WrittenFeedback { get; set; }

/// <summary>
/// The user submitted difficulty score for the puzzle.
/// </summary>
[Range(MinRating, MaxRating)]
public int Difficulty { get; set; }

/// <summary>
/// The user submitted fun score for the puzzle.
/// </summary>
[Range(MinRating, MaxRating)]
public int Fun { get; set; }
}
}
6 changes: 6 additions & 0 deletions ServerCore/Pages/Puzzles/Feedback.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<th>
@Html.DisplayNameFor(model => model.Feedbacks[0].Submitter)
</th>
<th>
@Html.DisplayNameFor(model => model.Feedbacks[0].Submitter.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Feedbacks[0].SubmissionTime)
</th>
Expand All @@ -46,6 +49,9 @@
<td>
@Html.DisplayFor(modelItem => item.Submitter.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Submitter.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.SubmissionTime)
</td>
Expand Down
4 changes: 2 additions & 2 deletions ServerCore/Pages/Puzzles/SubmitFeedback.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>
<div class="form-group">
<label asp-for="Feedback.Difficulty" class="control-label"></label>
<input asp-for="Feedback.Difficulty" type="range" min="@Model.MinRating" max="@Model.MaxRating" step="1" class="slider" id="difficultySlider">
<input asp-for="Feedback.Difficulty" type="range" min="@DataModel.Feedback.MinRating" max="@DataModel.Feedback.MaxRating" step="1" class="slider" id="difficultySlider">
<label id="difficultyLabel">NULL</label>
<script>
var diffslider = document.getElementById("difficultySlider");
Expand All @@ -41,7 +41,7 @@
</div>
<div class="form-group">
<label asp-for="Feedback.Fun" class="control-label"></label>
<input asp-for="Feedback.Fun" type="range" min="@Model.MinRating" max="@Model.MaxRating" step="1" class="slider" id="funSlider">
<input asp-for="Feedback.Fun" type="range" min="@DataModel.Feedback.MinRating" max="@DataModel.Feedback.MaxRating" step="1" class="slider" id="funSlider">
<label id="funLabel">NULL</label>
<script>
var funslider = document.getElementById("funSlider");
Expand Down
37 changes: 22 additions & 15 deletions ServerCore/Pages/Puzzles/SubmitFeedback.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public SubmitFeedbackModel(PuzzleServerContext serverContext, UserManager<Identi
[BindProperty]
public Feedback Feedback { get; set; }
public Puzzle Puzzle { get; set; }
public int MinRating = 1;
public int MaxRating = 10;

/// <summary>
/// Gets the submit feedback page for a puzzle
Expand All @@ -36,12 +34,14 @@ public async Task<IActionResult> OnGetAsync(int puzzleId)
}

// Seed existing feedback page
Feedback = await _context.Feedback.Where((f) => f.Puzzle.ID == puzzleId && f.Submitter == LoggedInUser).FirstOrDefaultAsync();
Feedback = await _context.Feedback
.Where((f) => (f.Puzzle.ID == puzzleId &&
f.Submitter == LoggedInUser))
.FirstOrDefaultAsync();

if (Feedback == null)
{
Feedback = new Feedback();
Feedback.Fun = 5;
Feedback.Difficulty = 5;
}

return Page();
Expand All @@ -59,16 +59,19 @@ public async Task<IActionResult> OnPostAsync(int puzzleId)
return Page();
}

if (Feedback.Fun < MinRating)
Feedback.Fun = MinRating;
if (Feedback.Fun > MaxRating)
Feedback.Fun = MaxRating;
if (Feedback.Difficulty < MinRating)
Feedback.Difficulty = MinRating;
if (Feedback.Difficulty > MaxRating)
Feedback.Difficulty = MaxRating;
Feedback.Fun = Math.Clamp(Feedback.Fun,
Feedback.MinRating,
Feedback.MaxRating);

Feedback.Difficulty = Math.Clamp(Feedback.Difficulty,
Feedback.MinRating,
Feedback.MaxRating);

Feedback editableFeedback = await _context.Feedback
.Where((f) => (f.Puzzle.ID == puzzleId &&
f.Submitter == LoggedInUser))
.FirstOrDefaultAsync();

Feedback editableFeedback = await _context.Feedback.Where((f) => f.Puzzle.ID == puzzleId && f.Submitter == LoggedInUser).FirstOrDefaultAsync();
if (editableFeedback == null)
{
Feedback.SubmissionTime = DateTime.UtcNow;
Expand All @@ -87,11 +90,15 @@ public async Task<IActionResult> OnPostAsync(int puzzleId)
editableFeedback.Difficulty = Feedback.Difficulty;
editableFeedback.Fun = Feedback.Fun;
editableFeedback.WrittenFeedback = Feedback.WrittenFeedback;
editableFeedback.Puzzle = await _context.Puzzles.Where(m => m.ID == puzzleId).FirstOrDefaultAsync();
editableFeedback.Puzzle = await _context.Puzzles
.Where(m => m.ID == puzzleId)
.FirstOrDefaultAsync();

if (editableFeedback.Puzzle == null)
{
return NotFound();
}

_context.Attach(editableFeedback).State = EntityState.Modified;
}

Expand Down