Exemplo n.º 1
0
 public CostCentreApplicationDTO Map(CostCentreApplication costCentreApplication)
 {
     if (costCentreApplication == null) return null;
     return Mapper.Map<CostCentreApplication, CostCentreApplicationDTO>(costCentreApplication);
 }
        public CreateCostCentreApplicationResponse CreateCostCentreApplication(Guid costCentreId,
            string applicationDescription)
        {
            if (string.IsNullOrEmpty(applicationDescription))
            {
                _log.Info("Failed to create cost centre application - you must include a description for the cost centre application");
                return new CreateCostCentreApplicationResponse
                           {
                               CostCentreApplicationId = Guid.Empty,
                               ErrorInfo = "you must include a description for the cost centre application"
                           };
            }
            CostCentre cc = _costCentreRepository.GetById(costCentreId);
            if (cc==null)
            {
                _log.Info("Failed to create cost centre application - you must include a valid cost centre in order to create a cost centre application");
                return new CreateCostCentreApplicationResponse
                           {
                               CostCentreApplicationId = Guid.Empty,
                               ErrorInfo =
                                   "you must include a valid cost centre in order to create a cost centre application"
                           };
            }
          
           
            //CostCentre cc = _costCentreRepository.GetById(costCentreId);
           


            CostCentreApplication app = new CostCentreApplication(Guid.NewGuid())
            {
                CostCentreId = costCentreId,
                Description = applicationDescription,
            };
            if (cc is DistributorSalesman )
            {
              var apps= _costCentreApplicationRepository.GetByCostCentreId(costCentreId).Where(s=>s._Status==EntityStatus.Active).ToList();
                apps.ForEach(n => _costCentreApplicationRepository.SetInactive(n));
                StartCleanUpThread(cc.Id, apps.Select(s=>s.Id).ToList());
               

            }
            if ( cc is Distributor ||  cc  is  Hub)
            {
                var application = _costCentreApplicationRepository.GetByCostCentreId(costCentreId).Where(s => s._Status == EntityStatus.Active).FirstOrDefault();
               // _costCentreRepository.Save(cc);
              
                if (application != null)
                {
                    _clientMasterDataTrackerRepository.IntializeApplication(application.Id);
                    app.Id = application.Id;
                }


            }
           
            Guid newCostCentreApplicationId = _costCentreApplicationRepository.Save(app);

            _log.InfoFormat("Created new cost centre application id {0} ", newCostCentreApplicationId);
            //also update command routing table so that it contains existing commands for the new costcentreapplicationid
          

            return new CreateCostCentreApplicationResponse { CostCentreApplicationId = newCostCentreApplicationId, ErrorInfo = "Success" };

        }
Exemplo n.º 3
0
        protected Guid AddDistributorCCApplication(Guid distributorId)
        {
            CostCentreApplication cca = new CostCentreApplication(Guid.NewGuid())
            {
                CostCentreId = distributorId,
                Description = "Test CC App"
            };

            return _costCentreApplicationRepository.Save(cca);
        }