Exemplo n.º 1
0
        protected void AskQUestion_Click(object sender, EventArgs e)
        {
            var user = this.User.Identity.Name;
            var context = new ApplicationDbContext();
            var dbUser = context.Users.FirstOrDefault(u => u.UserName == user);
            var title = this.TextBoxTitle.Text;
            var questText = this.QuestionText.Text;
            int categoryId = Convert.ToInt32(this.DropDownListCategories.SelectedItem.Value);
            var category = context.Categories.Find(categoryId);

            var newQ = new Models.Question
            {
                Title = title,
                Text = questText,
                User = dbUser,
                Category = category,
                DatePosted = DateTime.Now
            };

            context.Questions.Add(newQ);

            context.SaveChanges();

            ErrorSuccessNotifier.ShowAfterRedirect = true;
            ErrorSuccessNotifier.AddSuccessMessage("Question created");

            Response.Redirect("~/QuestionForm.aspx?id=" + newQ.Id);
        }
Exemplo n.º 2
0
        protected void AskQUestion_Click(object sender, EventArgs e)
        {
            var user       = this.User.Identity.Name;
            var context    = new ApplicationDbContext();
            var dbUser     = context.Users.FirstOrDefault(u => u.UserName == user);
            var title      = this.TextBoxTitle.Text;
            var questText  = this.QuestionText.Text;
            int categoryId = Convert.ToInt32(this.DropDownListCategories.SelectedItem.Value);
            var category   = context.Categories.Find(categoryId);

            var newQ = new Models.Question
            {
                Title      = title,
                Text       = questText,
                User       = dbUser,
                Category   = category,
                DatePosted = DateTime.Now
            };

            context.Questions.Add(newQ);

            context.SaveChanges();
            Response.Redirect("~/Default.aspx");
        }