Example #1
0
 public User Get(int id)
 {
     using (MssqllocaldbContext context = new MssqllocaldbContext())
     {
         return(context.Users.FirstOrDefault(n => n.Id == id));
     }
 }
Example #2
0
 public List <User> Get()
 {
     using (MssqllocaldbContext context = new MssqllocaldbContext())
     {
         return(context.Users.ToList());
     }
 }
Example #3
0
 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);
     }
 }
Example #4
0
 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());
         }
     }
 }
Example #5
0
 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());
         }
     }
 }
Example #6
0
 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);
     }
 }