public SingleRsp UpdateProduct(Product pro) { var res = new SingleRsp(); using (var context = new MyPhamContext()) { using (var tran = context.Database.BeginTransaction()) { try { if (checkCategory(pro.CatelogId)) { var t = context.Product.Update(pro); res.Data = pro; context.SaveChanges(); tran.Commit(); } else { tran.Rollback(); res.SetMessage("khong tim thay category"); } } catch (Exception e) { tran.Rollback(); res.SetError(e.StackTrace); } } } return(res); }
public SingleRsp DeleteUser(User dn) { var res = new SingleRsp(); using (var context = new MyPhamContext()) { using (var tran = context.Database.BeginTransaction()) { try { if (!common.checkExistbyID(dn.Id)) { var t = context.User.Remove(dn); res.Data = dn; context.SaveChanges(); tran.Commit(); } else { res.SetMessage("No User Match"); tran.Rollback(); } } catch (Exception e) { tran.Rollback(); res.SetError(e.StackTrace); } } } return(res); }
public SingleRsp CreateNewUser(User dn) { var res = new SingleRsp(); using (var context = new MyPhamContext()) { using (var tran = context.Database.BeginTransaction()) { try { if (common.checkExistbyUserName(dn.Username)) { var t = context.User.Add(dn); res.Data = dn; context.SaveChanges(); tran.Commit(); } else { res.SetMessage("Exist User"); tran.Rollback(); } } catch (Exception e) { tran.Rollback(); res.SetError(e.StackTrace); } } } return(res); }
public IActionResult LoginAsync([FromBody] LoginReq req) { var res = new SingleRsp(); User user = _svc.findByUserNameAndPassWord(req); /*UserWithToken userWithToken = null;*/ if (user != null) { /* RefreshToken refreshToken = GenerateRefreshToken(); *//* user.RefreshTokenNavigation.Add(refreshToken); *//* _context.RefreshToken.Add(refreshToken); */ _context.SaveChangesAsync(); /*userWithToken = new UserWithToken(user);*/ /* user.RefreshToken = refreshToken.Token; */ user.AccessToken = GenerateAccessToken(user); } else { res.SetMessage("Invalid Username or Password"); } /*if (userWithToken == null) * { * res.SetMessage("Cannot create token"); * }*/ /*else * { * userWithToken.AccessToken = GenerateAccessToken(user); * }*/ //sign your token here here.. res.Data = user; return(Ok(res)); }