public User Get(int id) { using (MssqllocaldbContext context = new MssqllocaldbContext()) { return(context.Users.FirstOrDefault(n => n.Id == id)); } }
public List <User> Get() { using (MssqllocaldbContext context = new MssqllocaldbContext()) { return(context.Users.ToList()); } }
public bool Delete(int id) { using (MssqllocaldbContext context = new MssqllocaldbContext()) { User user = context.Users.FirstOrDefault(n => n.Id == id); context.Users.Remove(user); context.SaveChanges(); return(true); } }
public IActionResult GetAccountInfo() { using (MssqllocaldbContext context = new MssqllocaldbContext()) { User existUser = context.Users.FirstOrDefault(n => n.Id == TokenProvider.GetUserId); if (existUser != null) { return(Ok(new { Token = TokenProvider.CreateToken(existUser.Id), User = existUser })); } else { return(NotFound()); } } }
public IActionResult Post(LoginModel model) { using (MssqllocaldbContext context = new MssqllocaldbContext()) { User existUser = context.Users.FirstOrDefault(n => n.Email == model.Email && n.Password == model.Password); if (existUser != null) { return(Ok(new { Token = TokenProvider.CreateToken(existUser.Id), User = existUser })); } else { return(Unauthorized()); } } }
public User Post(User user) { using (MssqllocaldbContext context = new MssqllocaldbContext()) { if (user.Id == 0) { context.Users.Add(user); } else { User existUser = context.Users.FirstOrDefault(n => n.Id == user.Id); existUser.Name = user.Name; existUser.Email = user.Email; existUser.Password = user.Password; existUser.CreateDate = user.CreateDate; } context.SaveChanges(); return(user); } }