コード例 #1
0
ファイル: RequestDAL.cs プロジェクト: MohamedMedina/SamDb
        public ICollection <RequestDTO> GetAllRequestsByStatusfromDB(int status)
        {
            ICollection <RequestDTO> outputList = default(ICollection <RequestDTO>);

            try
            {
                // 1- Select All Groups From DB
                RequestBusiness _RequestBusiness = new RequestBusiness();
                //RequestList _RequestList = _RequestBusiness.SelectRows(null, null, null, null, null, null, null, null,
                //    null, null, null, null, null, null, null, null);

                RequestList _RequestList = _RequestBusiness.SelectRows(null, null, null, null, null, null, null, null, null,
                                                                       null, null, null, null, status, null, null);

                if (_RequestList != null && _RequestList.Count > 0)
                //outputList = Mapper.MapUserAsOutput();
                {
                    // 2- Prepare Mapping Obects (Fill Values from DB)

                    //if(Mapper._RequestTypeList == default(List<RequestType>)) ==> In case we try to save DB hits (we apply that check for all lists)
                    //Mapper._RequestTypeList = fillRequestTypeList();

                    Mapper._RequestList         = _RequestList;
                    Mapper._RequestDetailList   = fillRequestDetailListbyRequestStatus(Mapper._RequestList);
                    Mapper._RequestTypeList     = fillRequestTypeList();
                    Mapper._RequestStatusList   = fillRequestStatusList();
                    Mapper._RequestClassList    = fillRequestClassList();
                    Mapper._RequestPriorityList = fillRequestPriorityList();
                    Mapper._RejectReasonList    = fillRejectReasonList();
                    Mapper._CardTypeList        = fillCardTypeList();
                    Mapper._CardValidityList    = fillCardValidityList();
                    Mapper._WorkFieldList       = fillWorkFieldList();
                    Mapper._CustomerList        = fillCustomerList();
                    Mapper._UserList            = fillUserList();

                    //UserGroupBusiness _UserGroupBusiness = new UserGroupBusiness();
                    //UserGroupList _UserGroupList = default(UserGroupList);

                    //foreach (User _User in _UserList)
                    //{
                    //    _UserGroupList = _UserGroupBusiness.SelectRows(null, _User.Id, null);

                    //    if (_UserGroupList != null && _UserGroupList.Count > 0)
                    //        foreach (UserGroup _UserGroup in _UserGroupList)
                    //            Mapper._UserGroupList.Add(Copier.copyUserGroup(_UserGroup));
                    //}


                    // 3- Perform Mapping to Output
                    outputList = Mapper.MapRequestAsOutput();
                }
            }
            catch (Exception ex)
            {
                // Log Exception Here
                throw; //new Exception(ex.Message);
            }

            return(outputList);
        }
コード例 #2
0
ファイル: RequestDAL.cs プロジェクト: MohamedMedina/SamDb
        public RequestDTO UpdateRequestinDB(RequestDTO requestDTO)
        {
            BaseDataAccess _db = new BaseDataAccess();

            using (DbTransaction dbTransaction = _db.CreateTransaction())
            {
                try
                {
                    // 1- Perform Mapping to  Input (for Saving in DB)
                    if (Mapper.MapRequestAsInput(requestDTO))
                    {
                        // 2- Select Request to be updated
                        RequestBusiness requestBusiness = new RequestBusiness();
                        RequestList     requestList     = requestBusiness.SelectRows(Mapper._Request.Id, null, null, null, null, null, null, null, null,
                                                                                     null, null, null, null, null, null, null);

                        if (requestList != null && requestList.Count > 0)
                        {
                            requestList[0].requestNumber     = Mapper._Request.requestNumber;
                            requestList[0].totalQuantity     = Mapper._Request.totalQuantity;
                            requestList[0].PDD               = Mapper._Request.PDD;
                            requestList[0].customerID        = Mapper._Request.customerID;
                            requestList[0].creationDate      = Mapper._Request.creationDate;
                            requestList[0].creationUserID    = Mapper._Request.creationUserID;
                            requestList[0].approvalDate      = Mapper._Request.approvalDate;
                            requestList[0].approvalUserID    = Mapper._Request.approvalUserID;
                            requestList[0].receiveDate       = Mapper._Request.receiveDate;
                            requestList[0].receiveUserID     = Mapper._Request.receiveUserID;
                            requestList[0].rejectionDate     = Mapper._Request.rejectionDate;
                            requestList[0].rejectionUserID   = Mapper._Request.rejectionUserID;
                            requestList[0].rejectionReasonID = Mapper._Request.rejectionReasonID;
                            requestList[0].requestTypeID     = Mapper._Request.requestTypeID;
                            requestList[0].requestStatusID   = Mapper._Request.requestStatusID;
                            requestList[0].requestCalssID    = Mapper._Request.requestCalssID;
                            requestList[0].requestPriorityID = Mapper._Request.requestPriorityID;

                            // 3- Update Request Data by Input Values
                            requestBusiness = new RequestBusiness();
                            if (requestBusiness.UpdateRow(dbTransaction, requestList[0]) > 0)
                            {
                                // 4- Remove Request Details Already Saved for that Request in DB
                                RequestDetailBusiness requestDetailBusiness = new RequestDetailBusiness();
                                RequestDetailList     requestDetailList     = requestDetailBusiness.SelectRows(null, null, Mapper._Request.Id);

                                if (requestDetailList != null && requestDetailList.Count > 0)
                                {
                                    foreach (RequestDetail requestDetail in requestDetailList)
                                    {
                                        requestDetailBusiness = new RequestDetailBusiness();
                                        requestDetailBusiness.DeleteRow(dbTransaction, requestDetail);
                                    }
                                }

                                // 5- Add New Request Details from Input
                                if (Mapper._RequestDetailListInput != null && Mapper._RequestDetailListInput.Count > 0)
                                {
                                    foreach (RequestDetail requestDetail in Mapper._RequestDetailListInput)
                                    {
                                        requestDetailBusiness = new RequestDetailBusiness();
                                        requestDetailBusiness.InsertRow(dbTransaction, requestDetail);
                                    }

                                    dbTransaction.Commit();
                                }
                            }
                            else
                            {
                                dbTransaction.Rollback();
                                throw new Exception("DataBase Operation Failure");
                            }
                        }
                        else
                        {
                            throw new Exception("Request Id Not Found in DB");
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException("requestDTO");
                    }
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    throw new Exception("DataBase Operation Failure");
                }
            }

            return(requestDTO);
        }