コード例 #1
0
        public IHttpActionResult Post(TestDetailsResponseModel model)
        {
            var currentUser = this.users
                .All()
                .FirstOrDefault(u => u.UserName == this.User.Identity.Name);

            var newTest = new Test
            {
                CourseId = model.CourseId
            };

            this.tests.Add(newTest);
            this.tests.SaveChanges();

            return this.Ok(newTest.Id);
        }
コード例 #2
0
        public IHttpActionResult Create(TestModel test)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newTest = new Test
            {
            };

            this.db.Tests.Add(newTest);
            this.db.SaveChanges();

            test.TestId = newTest.Id;

            return Ok(newTest);
        }
コード例 #3
0
        public IHttpActionResult Update(int id, Test test)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var existingTest = GetTestById(id);

            if (existingTest == null)
            {
                return BadRequest(NoSuchId);
            }

            this.db.SaveChanges();

            test.Id = existingTest.Id;
            return Ok(test);
        }