public ActionResult GetQuestionsModelForRepresentative(int repId) { QuestionsService service = new QuestionsService(); AskRepresentativeQuestionModel model = service.GetQuestionsmodelForRepresentative(repId, User.Identity.GetUserId()); return(PartialView("_AskRepresentativeQuestion", model)); }
public ActionResult AskRepresentative(AskRepresentativeQuestionModel model) { QuestionsService service = new QuestionsService(); if (!ModelState.IsValid) { return(PartialView("_AskRepresentativeQuestion", model)); } service.PostRepresentativeQuestion(model, User.Identity.GetUserId()); return(PartialView("_AskRepresentativeSuccess", model)); }
public bool PostRepresentativeQuestion(AskRepresentativeQuestionModel model, string userID) { using (var context = ApplicationDbContext.Create()) { var representative = context.Representatives .Where(x => x.RepresentativeID == model.RepresentativeID) .Include(x => x.Party) .FirstOrDefault(); if (representative == null) { return(false); } var user = context.Users.Where(x => x.Id == userID).FirstOrDefault(); if (user == null) { return(false); } var customQuestion = new Question { CreateTimeUtc = DateTime.UtcNow, Text = model.Text, IsSuggested = false, Verified = false }; context.Questions.Add(customQuestion); var answerToken = new AnswerToken { Representative = representative, Question = customQuestion, Token = Guid.NewGuid(), CreateTimeUtc = DateTime.UtcNow }; context.AnswerTokens.Add(answerToken); var question = new UserRepresentativeQuestion { ApplicationUserID = userID, CreateTimeUtc = DateTime.UtcNow, Question = customQuestion, AnswerToken = answerToken, Processed = false, Representative = representative }; context.UserRepresentativeQuestions.Add(question); context.SaveChanges(); return(true); } }