/// <summary>
        /// Provides a list of Subdistributor as a result of filtering the DB on specific filters
        /// </summary>
        /// <returns></returns>
        public List <Subdistributor> FilteredItems()
        {
            ResultManager.IsCorrect = false;
            List <Subdistributor> items = new List <Subdistributor>();

            try
            {
                // implement new pipeline filtering
                var subdistributorList = RetrieveAllToFilter();
                SubdistributorFilteringPipeline pipeline = new SubdistributorFilteringPipeline();

                if (Identity.CurrentUser.IsInRole(UserRole.EmployeeManagerOperation + "," + UserRole.EmployeeManagerView + "," + UserRole.EmployeeRTVOperation + "," + UserRole.EmployeeRTVView))
                {
                    List <string> zones = GetBayerEmployeeZones(CurrentUser.Id);
                    pipeline.Register(new ZoneListFilter(zones));
                }

                if (Identity.CurrentUser.IsInRole(UserRole.CustomerDistributorOperation + "," + UserRole.CustomerDistributorView))
                {
                    pipeline.Register(new RelatedByActiveContractDistributorIdFilter(CurrentUser.Id));
                }

                items = pipeline.Process(subdistributorList).ToList();
                ResultManager.IsCorrect = true;
            }
            catch (Exception ex)
            {
                ResultManager.Add(ErrorDefault, Trace + "Index.311: Error while retrieving Subdistributor list from DB: " + ex.Message);
            }
            return(items);
        }
Пример #2
0
        public ActionResult FilterByZones()
        {
            // get the Distributor list
            var subdistributorList = controller.RetrieveAllToFilter();

            // Construct the pipeline
            SubdistributorFilteringPipeline subdistributorPipeline = new SubdistributorFilteringPipeline();

            // Register the filters to be executed
            List <string> zones = new List <string> {
                "40R"
            };

            subdistributorPipeline.Register(new ZoneListFilter(zones));

            // Start pipeline processing
            var filteredSubdistributors = subdistributorPipeline.Process(subdistributorList);

            // At this point fetch data from DB
            var listedSubdistributors = filteredSubdistributors.ToList();

            // just sending the result for testing purposes, cannot serialize the entire object because of the circular references present from EF.

            var result = listedSubdistributors.Select(x => new Subdistributor
            {
                Id                         = x.Id,
                BNAddressId                = x.BNAddressId,
                BNLegalRepresentative      = x.BNLegalRepresentative,
                BusinessName               = x.BusinessName,
                IdB                        = x.IdB,
                RTVCreator_BayerEmployeeId = x.RTVCreator_BayerEmployeeId,
                Type                       = x.Type,
                WebSite                    = x.WebSite
            });

            string JsonResult = JsonConvert.SerializeObject(result, Formatting.Indented, new JsonSerializerSettings {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            });

            return(Content(JsonResult));
        }
        public List <Subdistributor> RetrieveAll()
        {
            // applying filtering pipeline
            List <Subdistributor> subdistributorFilteredList = null;

            try
            {
                // implementing filtering pipeline
                var subdistributorList = RetrieveAllToFilter();
                SubdistributorFilteringPipeline pipeline = new SubdistributorFilteringPipeline();

                //TODO: implement pipeline.Register(new RelatedByActiveContractDistributorIdFilter(CurrentUser.Id));

                subdistributorFilteredList = pipeline.Process(subdistributorList).ToList();

                ResultManager.IsCorrect = true;
            }
            catch (Exception ex)
            {
                ResultManager.Add(ErrorDefault, Trace + "RetrieveAll.511 Excepción al obtener el listado de convenios Bayer-Subdistribuidor: " + ex.Message);
            }
            return(subdistributorFilteredList);
        }