Ejemplo n.º 1
0
        public IActionResult Put([FromBody] QuizViewModel model)
        {
            // return a generic HTTP Status 500 (Server Error)
            // if the client payload is invalid.
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }
            // handle the insert (without object-mapping)
            var quiz = new Quiz();

            // properties taken from the request
            quiz.Title       = model.Title;
            quiz.Description = model.Description;
            quiz.Text        = model.Text;
            quiz.Notes       = model.Notes;
            // properties set from server-side
            quiz.CreatedDate      = DateTime.Now;
            quiz.LastModifiedDate = quiz.CreatedDate;
            // Set a temporary author using the Admin user's userId
            // as user login isn't supported yet: we'll change this later on.
            quiz.UserId = DbContext.Users.Where(u => u.UserName == "Admin").FirstOrDefault().Id;
            // add the new quiz
            DbContext.Quizzes.Add(quiz);
            // persist the changes into the Database.
            DbContext.SaveChanges();
            // return the newly-created Quiz to the client.
            return(new JsonResult(quiz.Adapt <QuizViewModel>(), JsonSettings));
        }
Ejemplo n.º 2
0
        public IActionResult Put([FromBody] QuizViewModel model)
        {
            // return a generic HTTP Status 500 (Server Error)
            // if the client payload is invalid.
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }
            // handle the insert (without object-mapping)
            var quiz = new Quiz
            {
                // properties taken from the request
                Title       = model.Title,
                Description = model.Description,
                Text        = model.Text,
                Notes       = model.Notes,
                // properties set from server-side
                CreatedDate = DateTime.Now
            };

            quiz.LastModifiedDate = quiz.CreatedDate;
            // Set a temporary author using the Admin user's userId
            // as user login isn't supported yet: we'll change this later on.
            // retrieve the current user's Id
            quiz.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            // add the new quiz
            DbContext.Quizzes.Add(quiz);
            // persist the changes into the Database.
            DbContext.SaveChanges();
            // return the newly-created Quiz to the client.
            return(new JsonResult(quiz.Adapt <QuizViewModel>(), JsonSettings));
        }
Ejemplo n.º 3
0
        public IActionResult Put([FromBody]QuizViewModel model)
        {
            // return a generic HTTP status 500 (Server Error)
            // if the client payload is invalid.
            if (model == null) return new StatusCodeResult(500);

            // handle the insert (without object-mapping)
            // properties taken from the request
            var quiz = new Quiz
            {
                Title = model.Title,
                Description = model.Description,
                Text = model.Text,
                Notes = model.Notes
            };

            // properties taken from server-side
            quiz.CreatedDate = DateTime.Now;
            quiz.LastModifiedDate = quiz.CreatedDate;

            // retrieve the current user's Id
            quiz.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            // add the new quiz
            DbContext.Quizzes.Add(quiz);
            DbContext.SaveChanges();

            // return the newly-created Quiz to the client.
            return new JsonResult(quiz.Adapt<QuizViewModel>(), JsonSettings);
        }
Ejemplo n.º 4
0
        public IActionResult Post([FromBody] QuizViewModel model)
        {
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            var quiz = new Quiz();

            quiz.Title       = model.Title;
            quiz.Description = model.Description;
            quiz.Text        = model.Text;
            quiz.Notes       = model.Notes;

            quiz.CreatedDate      = DateTime.Now;
            quiz.LastModifiedDate = quiz.CreatedDate;

            quiz.UserId = DbContext.Users.Where(u => u.UserName == "Admin").FirstOrDefault().Id;

            DbContext.Quizzes.Add(quiz);
            DbContext.SaveChanges();

            return(new JsonResult(
                       quiz.Adapt <QuizViewModel>(),
                       JsonSettings));
        }
Ejemplo n.º 5
0
        public IActionResult Post([FromBody] QuizViewModel model)
        {
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }
            var quiz = new Quiz();

            quiz.Title       = model.Title;
            quiz.Description = model.Description;
            quiz.Text        = model.Text;
            quiz.Notes       = model.Notes;


            quiz.CreatedDate      = DateTime.Now;
            quiz.LastModifiedDate = quiz.CreatedDate;

            quiz.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            DbContext.Quizzes.Add(quiz);

            DbContext.SaveChanges();

            return(new JsonResult(quiz.Adapt <QuizViewModel>(), JsonSettings));
        }
Ejemplo n.º 6
0
        public IActionResult Put([FromBody] QuizViewModel model)
        {
            //return a generic HTTP Status 500(Server Error)
            //if the client payload is invalid
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            var quiz = new Quiz();

            //properties taken from the request
            quiz.Title       = model.Title;
            quiz.Description = model.Description;
            quiz.Text        = model.Text;
            quiz.Notes       = model.Notes;

            //properties set from server-side
            quiz.CreatedDate      = DateTime.Now;
            quiz.LastModifiedDate = quiz.CreatedDate;

            //set a temporary author using the Admin user's userId
            //as user login isn't supported yet -> we'll change this later on
            quiz.UserId = base.DbContext.Users.Where(user => string.Equals(user.UserName, "Admin"))
                          .FirstOrDefault().Id;

            //add the new quiz to the database
            base.DbContext.Quizzes.Add(quiz);
            base.DbContext.SaveChanges();

            return(new JsonResult(quiz.Adapt <QuizViewModel>(), JsonSettings));
        }
Ejemplo n.º 7
0
        public IActionResult Put([FromBody] QuizViewModel model)
        {
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            var quiz = new Quiz
            {
                Title            = model.Title,
                Description      = model.Description,
                Text             = model.Text,
                Notes            = model.Notes,
                CreatedDate      = DateTime.Now,
                LastModifiedDate = DateTime.Now
            };

            //dummy until we retrieve the actual user
            //quiz.UserId = DbContext.Users.Where(u => u.UserName == "Admin").FirstOrDefault().Id;
            quiz.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            DbContext.Quizzes.Add(quiz);
            DbContext.SaveChanges();

            return(new JsonResult(quiz.Adapt <QuizViewModel>(), JsonSettings));
        }
Ejemplo n.º 8
0
        public IActionResult Put([FromBody] QuizViewModel model)
        {
            // return a generic HTTP Status 500 (Server Error)
            // if the client payload is invalid.
            if (model == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            var quiz = new Quiz {
                Title       = model.Title,
                Description = model.Description,
                Text        = model.Text,
                Notes       = model.Notes,

                CreatedDate = DateTime.Now
            };

            quiz.LastModifiedDate = quiz.CreatedDate;

            quiz.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            DbContext.Quizzes.Add(quiz);

            DbContext.SaveChanges();

            return(new JsonResult(quiz.Adapt <QuizViewModel>(),
                                  JsonSettings));
        }
Ejemplo n.º 9
0
        public IActionResult Put(QuizViewModel model)
        {
            //return a generit HTTP Status 500 (Server Error)
            //if the client payload is invalid.
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }
            //handle the insert without object mapping
            var quiz = new Quiz();

            //properties taken from the request
            quiz.Title       = model.Title;
            quiz.Description = model.Description;
            quiz.Text        = model.Text;
            quiz.Notes       = model.Notes;

            //properties set from server-side
            quiz.CreatedDate      = DateTime.Now;
            quiz.LastModifiedDate = quiz.CreatedDate;

            //Set a temporary author using the Admin user's userId
            quiz.UserId = DbContext.Users
                          .Where(u => u.UserName == "Admin").FirstOrDefault().Id;
            DbContext.Quizzes.Add(quiz);
            DbContext.SaveChanges();

            //return the newly-created Quiz to the client.
            return(new JsonResult(quiz.Adapt <QuizViewModel>(),
                                  new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }
Ejemplo n.º 10
0
        public IActionResult Put([FromBody] QuizViewModel model)
        {
            if (model == null)
            {
                // Return a generic HTTP Status 500 (Server Error)
                return(new StatusCodeResult(500));
            }

            var quiz = new Quiz
            {
                // Properties taken from the request
                Title       = model.Title,
                Description = model.Description,
                Text        = model.Text,
                Notes       = model.Notes,

                // Properties set from server-side
                CreatedDate      = DateTime.Now,
                LastModifiedDate = DateTime.Now,

                // Set a temporary author using the Admin user's Id
                // because the login isn't supported yet
                UserId = _dbContext.Users.Where(x => x.UserName == "Admin").FirstOrDefault().Id
            };

            _dbContext.Quizzes.Add(quiz);
            _dbContext.SaveChanges();

            return(new JsonResult(quiz.Adapt <QuizViewModel>(), JsonSettings));
        }
Ejemplo n.º 11
0
        public QuizViewModel PostQuiz(ApplicationDbContext context, QuizViewModel model)
        {
            var quiz = new Quiz
            {
                Title       = model.Title,
                Description = model.Description,
                Text        = model.Text,
                Notes       = model.Notes,

                CreatedDate      = DateTime.Now,
                LastModifiedDate = model.CreatedDate,

                UserId = model.UserId
            };

            context.Add(quiz);
            context.SaveChanges();

            return(quiz.Adapt <QuizViewModel>());
        }
Ejemplo n.º 12
0
        public IActionResult Put([FromBody] QuizViewModel model)
        {
            // throw new NotImplementedException();
            // return a generic HTTP Status 500 (Server Error)
            // if the client payload is invalid.
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            // handle the insert (without object-mapping)
            var quiz = new Quiz();

            //properties taken for the request
            quiz.Title       = model.Title;
            quiz.Description = model.Description;
            quiz.Text        = model.Text;
            quiz.Notes       = model.Notes;

            //properties set from server-side
            quiz.CreatedDate      = DateTime.Now;
            quiz.LastModifiedDate = quiz.CreatedDate;

            // retrieve the current user's Id
            quiz.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            // add the new quiz
            DbContext.Quizzes.Add(quiz);
            // persist the changes into the Database
            DbContext.SaveChanges();

            // return the newly-created Quiz to the client
            return(new JsonResult(quiz.Adapt <QuizViewModel>(),
                                  new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }