public async Task <IActionResult> PutDebug(int id, Debug debug)
        {
            if (id != debug.Id)
            {
                return(BadRequest());
            }

            _context.Entry(debug).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DebugExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <Student> > PostStudent(NewStudent student)
        {
            // if (StudentExists(student.Username))
            // {
            //     return BadRequest("Student already exists in the database");
            // }
            try
            {
                string  userId     = MicrosoftLearnUtil.GetUserId(student.Username);
                Student newStudent = new Student
                {
                    FirstName  = student.FirstName,
                    LastName   = student.LastName,
                    School     = student.School,
                    Username   = student.Username,
                    Email      = student.Email,
                    CreateDate = DateTime.Now,
                    UserId     = userId,
                    Score      = MicrosoftLearnUtil.GetXP(userId)
                };

                _context.Student.Add(newStudent);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetStudent", new { id = newStudent.Id }, newStudent));
            }
            catch (WebException)
            {
                return(BadRequest("Unable to find user, please check the username"));
            }
        }