Esempio n. 1
0
        public async Task <IActionResult> CreateQ(CreateQViewModel model)
        {
            if (ModelState.IsValid)
            {
                QueueDbModel Queue = new QueueDbModel
                {
                    Name          = model.Name,
                    Priority      = model.Priority,
                    About         = model.About,
                    Id            = model.Id,
                    TeacherName   = model.TeacherName,
                    OuthorName    = User.Identity.Name,
                    UsersName     = new List <string>(),
                    UsersPriority = new List <int>(),
                };
                await _db.Queues.AddAsync(Queue);

                _userManager.FindByNameAsync(User.Identity.Name).Result.QueuesAsOuthor.Add(Queue.Id);
                _userManager.FindByNameAsync(model.TeacherName).Result.QueuesAsTeacher.Add(Queue.Id);
                await _db.SaveChangesAsync();

                return(RedirectToAction("QView", "Queue", new { Queue.Id }));
            }
            return(View(model));
        }
Esempio n. 2
0
        public IActionResult Create(CreateQViewModel createQViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", createQViewModel));
            }

            var question = new Question()
            {
                DueTime = createQViewModel.QuestionDueTime,
                Subject = createQViewModel.QuestionText
            };

            _context.Questions.Add(question);

            _context.Answers.AddRange(
                new Answer()
            {
                AnswerText = createQViewModel.Answer1,
                Question   = question
            },
                new Answer()
            {
                AnswerText = createQViewModel.Answer2,
                Question   = question
            },
                new Answer()
            {
                AnswerText = createQViewModel.Answer3,
                Question   = question
            },
                new Answer()
            {
                AnswerText = createQViewModel.Answer4,
                Question   = question
            });

            _context.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }