示例#1
0
        public async Task <IActionResult> Create([FromBody] User user)
        {
            if (user == null)
            {
                return(StatusCode(403));
            }
            try
            {
                using (var dbContext = new ResistContext())
                {
                    User newUser = new User()
                    {
                        Username = user.Username
                    };

                    await dbContext.Users.AddAsync(newUser);

                    dbContext.SaveChanges();

                    return(Json(newUser));
                }
            }
            catch
            {
                return(StatusCode(500));
            }
        }
示例#2
0
 public IActionResult Index()
 {
     using (var dbContext = new ResistContext())
     {
         List <User> users = dbContext.Users.ToList();
         if (users == null)
         {
             users = new List <User>();
         }
         return(Json(users));
     }
 }
示例#3
0
 public GamesController(ResistContext context)
 {
     _context = context;
 }