public SolutionDetail(Sql.Models.Solution solution, UserViewModel author, int votes, IUrlHelper urlHelper) { _solution = solution; Author = author; DeleteSolutionUrl = urlHelper.Action(new UrlActionContext { Action = "DeleteAsync", Controller = "Solution", Values = new { id = solution.SolutionId } }); UpvoteUrl = urlHelper.Action(new UrlActionContext { Action = "Upvote", Controller = "Solution", Values = new { itemId = Id } }); DownvoteUrl = urlHelper.Action(new UrlActionContext { Action = "Downvote", Controller = "Solution", Values = new { itemId = Id } }); ContentUrl = urlHelper.Action(new UrlActionContext { Action = "Details", Controller = "Solution", Values = new { id = Id } }); Votes = votes; }
public async Task <IActionResult> PostAsync(Sql.Models.Solution solution) { if (solution == null) { throw new ArgumentNullException(nameof(solution)); } if (string.IsNullOrWhiteSpace(solution.Content)) { throw new Exception("Content is required for solution."); } var user = await GetRequestUser(); solution.Author = user; await Repository.Solutions.Create(solution); return(Redirect("/Problem/Index/" + solution.ProblemId)); }