public ActionResult ThemMoi(string ten, string tenNgan, int maNguoiQuanLy, int maNhomCha, List <int> lstThanhVien) { try { int result = 0; NhomModel nhom = new NhomModel(); nhom.MaNguoiQL = maNguoiQuanLy; nhom.MaNhomCha = maNhomCha; if (maNhomCha != 0) { var parentCode = _rpGroup.LayChuoiMaCha(maNhomCha); nhom.ChuoiMaCha = parentCode + "." + maNhomCha; } else { nhom.ChuoiMaCha = "0"; } nhom.Ten = ten; nhom.TenNgan = tenNgan; result = _rpGroup.Them(nhom, lstThanhVien, GlobalData.User.IDUser); if (result > 0) { return(ToResponse(true, null, result)); } return(ToResponse(false, "Không thành công", 0)); } catch (BusinessException ex) { return(ToResponse(false, ex.Message, 0)); } }
public ActionResult LuuSua(int maNhom, string ten, string tenNgan, int maNguoiQuanLy, int maNhomCha, List <int> lstThanhVien) { try { bool result = false; NhomModel nhom = new NhomModel(); nhom.ID = maNhom; nhom.MaNguoiQL = maNguoiQuanLy; nhom.MaNhomCha = maNhomCha; if (maNhomCha != 0) { var parentCode = _rpGroup.LayChuoiMaCha(maNhomCha); nhom.ChuoiMaCha = parentCode + "." + maNhomCha; } else { nhom.ChuoiMaCha = "0"; } nhom.Ten = ten; nhom.TenNgan = tenNgan; result = _rpGroup.Sua(nhom, lstThanhVien); if (result) { return(ToResponse(true, null, result)); } return(ToResponse(false)); } catch (BusinessException ex) { return(ToResponse(false, ex.Message, null)); } }
public async Task <IActionResult> Put(NhomModel model) { if (!string.IsNullOrEmpty(model.TenNhom)) { var find = await _context.Set <Nhom>().FirstOrDefaultAsync(x => x.MaNhom == model.MaNhom); if (find != null) { find.MaNhom = model.MaNhom; find.TenNhom = model.TenNhom; _context.Set <Nhom>().Attach(find); await _context.SaveChangesAsync(); return(Ok("Saved")); } else { return(NotFound()); } } else { return(BadRequest()); } }
public bool Sua(NhomModel nhom, List <int> lstThanhVien) { using (var session = LOANSessionManager.OpenSession()) using (var transaction = session.BeginTransaction(IsolationLevel.RepeatableRead)) { try { IDbCommand commandNhom = new SqlCommand(); commandNhom.Connection = session.Connection; commandNhom.CommandType = CommandType.StoredProcedure; commandNhom.CommandText = "sp_NHOM_Sua"; session.Transaction.Enlist(commandNhom); commandNhom.Parameters.Add(new SqlParameter("@ID", nhom.ID)); commandNhom.Parameters.Add(new SqlParameter("@MaNhomCha", nhom.MaNhomCha)); commandNhom.Parameters.Add(new SqlParameter("@MaNguoiQL", nhom.MaNguoiQL)); commandNhom.Parameters.Add(new SqlParameter("@TenVietTat", nhom.TenNgan)); commandNhom.Parameters.Add(new SqlParameter("@Ten", nhom.Ten)); commandNhom.Parameters.Add(new SqlParameter("@ChuoiMaCha", nhom.ChuoiMaCha)); commandNhom.ExecuteNonQuery(); IDbCommand commandXoaNhanVienNhom = new SqlCommand(); commandXoaNhanVienNhom.Connection = session.Connection; commandXoaNhanVienNhom.CommandType = CommandType.StoredProcedure; commandXoaNhanVienNhom.CommandText = "sp_NHAN_VIEN_NHOM_Xoa"; session.Transaction.Enlist(commandXoaNhanVienNhom); commandXoaNhanVienNhom.Parameters.Add(new SqlParameter("@MaNhom", nhom.ID)); commandXoaNhanVienNhom.ExecuteNonQuery(); IDbCommand commandNhanVienNhom = new SqlCommand(); commandNhanVienNhom.Connection = session.Connection; commandNhanVienNhom.CommandType = CommandType.StoredProcedure; commandNhanVienNhom.CommandText = "sp_NHAN_VIEN_NHOM_Them"; session.Transaction.Enlist(commandNhanVienNhom); if (lstThanhVien != null) { for (int i = 0; i < lstThanhVien.Count; i++) { commandNhanVienNhom.Parameters.Clear(); commandNhanVienNhom.Parameters.Add(new SqlParameter("@MaNhom", nhom.ID)); commandNhanVienNhom.Parameters.Add(new SqlParameter("@MaNhanVien", lstThanhVien[i])); commandNhanVienNhom.ExecuteNonQuery(); } } transaction.Commit(); return(true); } catch (BusinessException ex) { transaction.Rollback(); throw ex; } } }
public int Them(NhomModel nhom, List <int> lstThanhVien, int createdBy) { using (var session = LOANSessionManager.OpenSession()) using (var transaction = session.BeginTransaction(IsolationLevel.RepeatableRead)) { try { IDbCommand commandNhom = new SqlCommand(); commandNhom.Connection = session.Connection; commandNhom.CommandType = CommandType.StoredProcedure; commandNhom.CommandText = "sp_NHOM_Them"; session.Transaction.Enlist(commandNhom); commandNhom.Parameters.Add(new SqlParameter("@ID", SqlDbType.BigInt) { Direction = ParameterDirection.Output }); commandNhom.Parameters.Add(new SqlParameter("@MaNhomCha", nhom.MaNhomCha)); commandNhom.Parameters.Add(new SqlParameter("@MaNguoiQL", nhom.MaNguoiQL)); commandNhom.Parameters.Add(new SqlParameter("@TenVietTat", nhom.TenNgan)); commandNhom.Parameters.Add(new SqlParameter("@Ten", nhom.Ten)); commandNhom.Parameters.Add(new SqlParameter("@ChuoiMaCha", nhom.ChuoiMaCha)); commandNhom.Parameters.Add(new SqlParameter("@createdBy", createdBy)); commandNhom.ExecuteNonQuery(); int maNhom = Convert.ToInt32((((SqlParameter)commandNhom.Parameters["@ID"]).Value).ToString()); IDbCommand commandNhanVienNhom = new SqlCommand(); commandNhanVienNhom.Connection = session.Connection; commandNhanVienNhom.CommandType = CommandType.StoredProcedure; commandNhanVienNhom.CommandText = "sp_NHAN_VIEN_NHOM_Them"; session.Transaction.Enlist(commandNhanVienNhom); if (lstThanhVien != null) { for (int i = 0; i < lstThanhVien.Count; i++) { commandNhanVienNhom.Parameters.Clear(); commandNhanVienNhom.Parameters.Add(new SqlParameter("@MaNhom", maNhom)); commandNhanVienNhom.Parameters.Add(new SqlParameter("@MaNhanVien", lstThanhVien[i])); commandNhanVienNhom.ExecuteNonQuery(); } } transaction.Commit(); return(maNhom); } catch (BusinessException ex) { transaction.Rollback(); throw ex; } } }
public async Task <IActionResult> Post(NhomModel model) { model.MaNhom = _context.Nhoms.Count() + 1; if (!string.IsNullOrEmpty(model.MaNhom.ToString())) { _context.Set <Nhom>().Add(new Nhom { MaNhom = model.MaNhom, TenNhom = model.TenNhom }); await _context.SaveChangesAsync(); return(Ok("Added")); } else { return(BadRequest()); } }