public async Task <ActionResult> Ask(QuestionCreateRequest request, CancellationToken cancel) { var command = new QuestionCreateCommand(request.Title, request.Content, _markdown.TransformIntoHTML(request.Content), DateTime.Now, request.Tags); var result = await _mediator.ExecuteAsync <QuestionCreateCommand, QuestionCreateCommandResult>(command, User.GetAppIdentity(), cancel); return(RedirectToRoute("QuestionRead", new { id = result.Id, slug = result.Slug, action = "get" })); }
public async Task <ActionResult> Vote(AnswerVoteRequest request, CancellationToken cancel) { var command = new AnswerVoteCommand(request.QuestionId, request.AnswerId, request.Upvote); var result = await _mediator.ExecuteAsync <AnswerVoteCommand, AnswerVoteCommandResult>(command, User.GetAppIdentity(), cancel); return(Json(new { Votes = result.Votes })); }
public async Task <ActionResult> Login(LoginModel model, CancellationToken cancel) { if (ModelState.IsValid) { var command = new AuthenticateCommand(model.Username, model.Password); var result = await _mediator.ExecuteAsync <AuthenticateCommand, AuthenticateCommandResult>(command, User.GetAppIdentity(), cancel); var ticket = new FormsAuthenticationTicket(1, model.Username, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), true, result.SessionId); var cookie = FormsAuthentication.Encrypt(ticket); Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, cookie)); if (!String.IsNullOrWhiteSpace(model.ReturnUrl) && Url.IsLocalUrl(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } } return(RedirectToRoute("Default")); }
private void AppendQuestion(XElement question, ConcurrentDictionary <String, String> idmap, IDictionary <String, String> usermap) { if (question.Attribute("OwnerUserId") == null || question.Attribute("Id") == null) { return; } var id = question.Attribute("Id").Value; var userId = question.Attribute("OwnerUserId").Value; var user = new SimpleQAPrincipal(usermap[userId], "whatever", "", 0); var tags = Regex.Matches(question.Attribute("Tags").Value, "<(.*?)>") .OfType <Match>() .Select(m => m.ToString()) .Select(s => s.Substring(1, s.Length - 2)) .ToArray(); var creationDate = DateTime.Parse(question.Attribute("CreationDate").Value); var views = Int32.Parse(question.Attribute("ViewCount").Value); var command = new QuestionCreateCommand(question.Attribute("Title").Value, question.Attribute("Body").Value, question.Attribute("Body").Value, creationDate, tags); var sw = new Stopwatch(); sw.Start(); var result = _mediator.ExecuteAsync <QuestionCreateCommand, QuestionCreateCommandResult>(command, user.GetAppIdentity(), CancellationToken.None).Result; sw.Stop(); var viewCommand = new VisitQuestionCommand(result.Id, views); _mediator.ExecuteAsync <VisitQuestionCommand, VisitQuestionCommandResult>(viewCommand, user.GetAppIdentity(), CancellationToken.None).Wait(); Console.WriteLine("Added question: " + result.Slug + ", " + question.Attribute("Body").Value.Length + " chars in " + sw.ElapsedMilliseconds + " ms."); idmap.TryAdd(id, result.Id); }
public IDictionary <String, String> Process(XDocument doc) { var users = doc.Element("users").Elements(); var idmap = new ConcurrentDictionary <String, String>(); var anonymous = new SimpleQAIdentity("", "dumpprocessor", "", 0); Parallel.ForEach(users, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, user => { var command = new AuthenticateCommand(user.Attribute("DisplayName").Value, "whatever"); var result = _mediator.ExecuteAsync <AuthenticateCommand, AuthenticateCommandResult>(command, anonymous, CancellationToken.None).Result; idmap.TryAdd(user.Attribute("Id").Value, _channel.Execute("HGET {user}:namemapping @Username", new { command.Username })[0].GetString()); _channel.Execute("sadd {user}:builtin @user", new { user = command.Username }).ThrowErrorIfAny(); Console.WriteLine("Added user: " + command.Username); }); return(idmap); }
private void VoteAnswer(SimpleQAIdentity user, String questionId, String answerId) { var command = new AnswerVoteCommand(questionId, answerId, true); var result = _mediator.ExecuteAsync <AnswerVoteCommand, AnswerVoteCommandResult>(command, user, CancellationToken.None).Result; }
public async Task <ActionResult> Visit(String questionId, CancellationToken cancel) { await _mediator.ExecuteAsync <VisitQuestionCommand, VisitQuestionCommandResult>(new VisitQuestionCommand(questionId), User.GetAppIdentity(), cancel).ConfigureAwait(false); return(new HttpStatusCodeResult(HttpStatusCode.NoContent)); }