public AffidavitDetailsDTO GetAffidavitDetailsByCustId(int CustId)
        {
            AffidavitDetailsDTO affidavitDetails = new AffidavitDetailsDTO();
            AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<affidavitdetail>>()
                .GetSingle(item => item.Affidavit_CustID == CustId), affidavitDetails);

            return affidavitDetails;
        }
 public int SaveAffidavitDetails(AffidavitDetailsDTO affidavitdetail)
 {
     affidavitdetail affidavitdetailEntity = new affidavitdetail();
     using (TransactionScope transactionScope = new TransactionScope())
     {
         AutoMapper.Mapper.Map(affidavitdetail, affidavitdetailEntity);
         if (affidavitdetail.AffidavitDetailsId == 0)
         {
             ESalesUnityContainer.Container.Resolve<IGenericRepository<affidavitdetail>>().Save(affidavitdetailEntity);
         }
         transactionScope.Complete();
     }
     return affidavitdetailEntity.AffidavitDetailsId;
 }
        public int UpdateAffidavitDetails(AffidavitDetailsDTO AffidavitDetails)
        {
            affidavitdetail affidavitDetailsEntity = new affidavitdetail();
            int affidavitDetailsId;
            using (TransactionScope transactionScope = new TransactionScope())
            {
                AutoMapper.Mapper.Map(AffidavitDetails, affidavitDetailsEntity);
                ESalesUnityContainer.Container.Resolve<IGenericRepository<affidavitdetail>>().Update(affidavitDetailsEntity);
                affidavitDetailsId = AffidavitDetails.AffidavitDetailsId;
                
                transactionScope.Complete();
            }

            return affidavitDetailsId;
        }
    public void LoadReport(string Truckno)
    {
        SMSRegistrationDTO _smsRegistrationObj = new SMSRegistrationDTO();
         _smsRegistrationObj = ESalesUnityContainer.Container.Resolve<ISMSService>().GetPreviousdDateSMSDetailsByTruckNo(Truckno);
         SettlementOfAccountsDTO lastSettlementdetails = ESalesUnityContainer.Container.Resolve<ISettlementOfAccountsService>().GetLastSettlementOfAccountsByTruckNo(Truckno);
         if (lastSettlementdetails.Account_Id > 0)
         {
             _smsRegistrationObj.SMSReg_Last_Settlement_CreatedDate = lastSettlementdetails.Account_CreatedDate.ToString();
             _smsRegistrationObj.SMSReg_Last_Settlement_Dist = lastSettlementdetails.Account_Booking_Cust_District_Name;
         }
         AffidavitDetailsDTO _affidavitDetails = new AffidavitDetailsDTO();
         _affidavitDetails = ESalesUnityContainer.Container.Resolve<IAffidavitDetails>().GetAffidavitDetailsByCustId(_smsRegistrationObj.SMSReg_CustId);
        List<SMSRegistrationDTO> lstLoadingSMSBookingRpt = new List<SMSRegistrationDTO>();
        lstLoadingSMSBookingRpt.Add(_smsRegistrationObj);
        
        
        //Reset report viewer control
        reportViewer.Reset();

        //Initializes report viewer and set report as embedded resource
        Common.SetReportEmbeddedResource(reportViewer, "TCESS.ESales.CommonLayer.Reports.Printingreport.rdlc");

        ReportDataSource loadingSMSBookingDataSource = new ReportDataSource("dsSMSBookingReport", lstLoadingSMSBookingRpt);
        reportViewer.LocalReport.DataSources.Add(loadingSMSBookingDataSource);

        string affidavitStatus = string.Empty;

        if (_affidavitDetails.Affidavit_CustID > 0)
        {
            affidavitStatus = "Yes";
        }
        else
        {
            affidavitStatus = "No";
        }

        ReportParameter Affidavit = new ReportParameter("Affidavit", affidavitStatus);

        reportViewer.LocalReport.SetParameters(new ReportParameter[] { Affidavit });
    }
    private void GetAndSetAffidavitDetails()
    {
        AffidavitDetailsDTO affidavitDetail = ESalesUnityContainer.Container.Resolve<IAffidavitDetails>()
            .GetAffidavitDetailsByCustId(Convert.ToInt32(ViewState[Globals.StateMgmtVariables.CUSTOMERID]));

        if (affidavitDetail.AffidavitExpiryDate > DateTime.Now)
        {
            ucMessageBox.ShowMessage("Affidavit Already submitted");
        }
        else
        {
            if (affidavitDetail.Affidavit_CustID > 0)
            {
                affidavitDetail.AffidavitSubmitDate = DateTime.Now;
                affidavitDetail.AffidavitExpiryDate = DateTime.Now.AddYears(1);
                int result = ESalesUnityContainer.Container.Resolve<IAffidavitDetails>().UpdateAffidavitDetails(affidavitDetail);

                if (result > 0)
                {
                    ucMessageBox.ShowMessage("Affidavit Saved Successfully");
                }
            }
            else
            {
                AffidavitDetailsDTO affidavitDetails = new AffidavitDetailsDTO();
                affidavitDetails.Affidavit_CustID = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.CUSTOMERID]);
                affidavitDetails.AffidavitCreatedBy = GetCurrentUserId();
                affidavitDetails.AffidavitCreatedDate = DateTime.Now;
                affidavitDetails.AffidavitSubmitDate = DateTime.Now;
                affidavitDetails.AffidavitExpiryDate = DateTime.Now.AddYears(1);
                affidavitDetails.AffidavitIsSubmitted = 1;

                int result = ESalesUnityContainer.Container.Resolve<IAffidavitDetails>().SaveAffidavitDetails(affidavitDetails);

                if (result > 0)
                {
                    ucMessageBox.ShowMessage("Affidavit Saved Successfully");
                    FillGridWithCustomerDetails(txtCustomerCode.Text.Trim(), txtPANNo.Text.Trim());
                }
            }
        }
    }