Esempio n. 1
0
        private List <GroupFunction> fillGroupFunctionList()
        {
            GroupFunctionBusiness _GroupBusiness     = new GroupFunctionBusiness();
            GroupFunctionList     _GroupFunctionList = _GroupBusiness.SelectRows(null, null, null);

            return(_GroupFunctionList);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public GroupDTO AddGrouptoDB(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))
                    {
                        ////User user = Mapper._User;
                        ////List<UserGroup> userGroups = Mapper._UserGroupListInput;
                        //Mapper._User.createDate = DateTime.Now;

                        // 2- Insert Group in DB
                        GroupBusiness groupBusiness = new GroupBusiness();
                        if (groupBusiness.InsertRow(dbTransaction, Mapper._Group) > 0)
                        {
                            groupDTO.Id = Mapper._Group.Id;

                            if (Mapper._GroupFunctionListInput != null && Mapper._GroupFunctionListInput.Count > 0)
                            {
                                GroupFunctionBusiness groupFunctionBusiness = new GroupFunctionBusiness();

                                // 3- Insert Group Functions in DB
                                foreach (GroupFunction groupFunction in Mapper._GroupFunctionListInput)
                                {
                                    groupFunction.groupId = Mapper._Group.Id;

                                    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);
        }