private List <GroupFunction> fillGroupFunctionList() { GroupFunctionBusiness _GroupBusiness = new GroupFunctionBusiness(); GroupFunctionList _GroupFunctionList = _GroupBusiness.SelectRows(null, null, null); return(_GroupFunctionList); }
public bool DeleteGroupfromDB(int id) { bool result = default(bool); BaseDataAccess _db = new BaseDataAccess(); using (DbTransaction dbTransaction = _db.CreateTransaction()) { try { // 1- Select User From DB by ID GroupBusiness groupBusiness = new GroupBusiness(); GroupList groupList = groupBusiness.SelectRows(id, null); if (groupList != null && groupList.Count > 0) { // 2- Select Group Functions From DB by Group ID GroupFunctionBusiness _GroupFunctionBusiness = new GroupFunctionBusiness(); GroupFunctionList groupFunctionList = _GroupFunctionBusiness.SelectRows(null, null, id); if (groupFunctionList != null && groupFunctionList.Count > 0) { // 3- Delete Group Functions first (we must remove children first because of DB relation) foreach (GroupFunction groupFunction in groupFunctionList) { _GroupFunctionBusiness = new GroupFunctionBusiness(); _GroupFunctionBusiness.DeleteRow(dbTransaction, groupFunction); } } // 4- Then Delete The Group itself groupBusiness = new GroupBusiness(); if (groupBusiness.DeleteRow(dbTransaction, groupList[0]) > 0) { dbTransaction.Commit(); result = true; } else { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } else { dbTransaction.Rollback(); throw new Exception("Group Id Not Found in DB"); } } catch (Exception) { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } return(result); }
public GroupDTO UpdateGroupinDB(GroupDTO groupDTO) { BaseDataAccess _db = new BaseDataAccess(); using (DbTransaction dbTransaction = _db.CreateTransaction()) { try { // 1- Perform Mapping to Input (for Saving in DB) if (Mapper.MapGroupAsInput(groupDTO)) { // 2- Select Group to be updated GroupBusiness groupBusiness = new GroupBusiness(); GroupList groupList = groupBusiness.SelectRows(Mapper._Group.Id, null); if (groupList != null && groupList.Count > 0) { groupList[0].name = Mapper._Group.name; groupList[0].status = Mapper._Group.status; // 3- Update Group Data by Input Values groupBusiness = new GroupBusiness(); if (groupBusiness.UpdateRow(dbTransaction, groupList[0]) > 0) { // 4- Remove Group Functions Already Saved for that Group in DB GroupFunctionBusiness groupFunctionBusiness = new GroupFunctionBusiness(); GroupFunctionList groupFunctionList = groupFunctionBusiness.SelectRows(null, null, Mapper._Group.Id); if (groupFunctionList != null && groupFunctionList.Count > 0) { foreach (GroupFunction groupFunction in groupFunctionList) { groupFunctionBusiness = new GroupFunctionBusiness(); groupFunctionBusiness.DeleteRow(dbTransaction, groupFunction); } } // 5- Add New Group Functions from Input if (Mapper._GroupFunctionListInput != null && Mapper._GroupFunctionListInput.Count > 0) { foreach (GroupFunction groupFunction in Mapper._GroupFunctionListInput) { groupFunctionBusiness = new GroupFunctionBusiness(); groupFunctionBusiness.InsertRow(dbTransaction, groupFunction); } dbTransaction.Commit(); } } else { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } else { throw new Exception("Group Id Not Found in DB"); } } else { throw new ArgumentNullException("groupDTO"); } } catch (Exception ex) { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } return(groupDTO); }