// GET: Depots
        public ActionResult Index(int?id)
        {
            DepotViewModel depotViewModel = new DepotViewModel();

            if (id != null)
            {
                Depot depot = depotService.GetDepotById(id);

                depotViewModel = new DepotViewModel()
                {
                    Id              = depot.Id,
                    IsActive        = depot.IsActive,
                    Code            = depot.Code,
                    GeolocationId   = depot.GeolocationId,
                    GeolocationName = depot.Geolocation.Address,
                    DepotTypeId     = depot.DepotTypeId,
                    DepotTypeName   = depot.DepotType.Name
                };
            }

            ViewBag.DepotTypeList   = new SelectList(genericService.GetList <DepotType>(), "Id", "Name");
            ViewBag.GeolocationList = new SelectList(geolocationService.GetGeolocationList().Select(g => new { Id = g.Id, Name = g.Address + ", " + g.City.Name }), "Id", "Name");

            return(View(depotViewModel));
        }
        public JsonResult GetDepotDrugTypes(int?depotId)
        {
            DepotDTO       depotDto   = depots.GetById(depotId);
            DepotViewModel depotModel = new DepotViewModel()
            {
                Depot          = depotDto,
                DepotDrugUnits = drugUnits.GetByDepot(depotDto?.DepotId)
            };

            return(Json(depotModel.DepotDrugTypes, JsonRequestBehavior.AllowGet));
        }
        private DepotViewModel MapDepotDTOToViewModel(DepotDTO dto)
        {
            DepotViewModel returnDepot = new DepotViewModel()
            {
                Id          = dto.Id,
                Location    = dto.Location,
                DepotTracks = new List <TrackViewModel>()
            };

            foreach (TrackDTO track in dto.DepotTracks)
            {
                returnDepot.DepotTracks.Add(_mapper.Map <TrackViewModel>(track));
            }
            return(returnDepot);
        }
        private DepotDTO MapDepotViewModelToDTO(DepotViewModel depotViewModel)
        {
            DepotDTO returnDepot = new DepotDTO()
            {
                Id          = depotViewModel.Id,
                Location    = depotViewModel.Location,
                DepotTracks = new List <TrackDTO>()
            };

            foreach (TrackViewModel track in depotViewModel.DepotTracks)
            {
                returnDepot.DepotTracks.Add(_mapper.Map <TrackDTO>(track));
            }
            return(returnDepot);
        }
Ejemplo n.º 5
0
        private IEnumerable <CompanyViewModel> GetCompanyViewModels()
        {
            //List<StrategicBusinessUnitViewModel> sbuViewModels = new List<StrategicBusinessUnitViewModel>();

            List <CompanyViewModel> companyViewModels = new List <CompanyViewModel>();

            try
            {
                using (ASJDE context = new ASJDE())
                {
                    IQueryable <Company> companies = (from c in context.Companies select c);

                    foreach (Company company in companies)
                    {
                        CompanyViewModel companyViewModel = new CompanyViewModel();
                        companyViewModel.Name = company.Entity.Name;
                        companyViewModel.StrategicBusinessUnitViews = new List <StrategicBusinessUnitViewModel>();

                        Company co = company;
                        IQueryable <StrategicBusinessUnit> sbus = (from s in context.StrategicBusinessUnits
                                                                   where s.Entity.EntityStatus.ID == 1 &&
                                                                   s.CompanyID == co.ID
                                                                   select s);

                        foreach (var strategicBusinessUnit in sbus)
                        {
                            StrategicBusinessUnitViewModel sbuViewModel = new StrategicBusinessUnitViewModel();
                            sbuViewModel.Name          = strategicBusinessUnit.Entity.Name;
                            sbuViewModel.OBUViewModels = new List <OperationalBusinessUnitViewModel>();

                            StrategicBusinessUnit sbUnit = strategicBusinessUnit;

                            IQueryable <OperationalBusinessUnit> obs = (from o in context.OperationalBusinessUnits
                                                                        where o.Entity.EntityStatus.ID == 1 &&
                                                                        o.StrategicBusinessUnitID == sbUnit.ID
                                                                        select o);

                            foreach (var operationalBusinessUnit in obs)
                            {
                                OperationalBusinessUnitViewModel obuViewModel = new OperationalBusinessUnitViewModel();
                                obuViewModel.Name         = operationalBusinessUnit.Entity.Name;
                                obuViewModel.BUViewModels = new List <BusinessUnitViewModel>();

                                OperationalBusinessUnit   bUnit = operationalBusinessUnit;
                                IQueryable <BusinessUnit> bus   = (from b in context.BusinessUnits
                                                                   where b.Entity.EntityStatus.ID == 1 &&
                                                                   b.OperationalBusinessUnitID == bUnit.ID
                                                                   select b);

                                foreach (var bu in bus)
                                {
                                    BusinessUnitViewModel buViewModel = new BusinessUnitViewModel();
                                    buViewModel.Name             = bu.Entity.Name;
                                    buViewModel.BranchViewModels = new List <BranchViewModel>();

                                    BusinessUnit        bu1     = bu;
                                    IQueryable <Branch> branchs = (from br in context.Branches
                                                                   where br.Entity.EntityStatus.ID == 1 &&
                                                                   br.BusinessUnitID == bu1.ID
                                                                   select br);

                                    foreach (var branch in branchs)
                                    {
                                        BranchViewModel branchViewModel = new BranchViewModel();
                                        branchViewModel.Name            = branch.Entity.Name;
                                        branchViewModel.DepotViewModels = new List <DepotViewModel>();

                                        Branch branch1 = branch;
                                        var    depots  = (from d in context.Depots
                                                          where d.Entity.EntityStatus.ID == 1 &&
                                                          d.BranchID == branch1.ID
                                                          select d);
                                        foreach (var depot in depots)
                                        {
                                            DepotViewModel depotViewModel = new DepotViewModel();
                                            depotViewModel.Name = depot.Entity.Name;

                                            branchViewModel.DepotViewModels.Add(depotViewModel);
                                        }

                                        buViewModel.BranchViewModels.Add(branchViewModel);
                                    }

                                    obuViewModel.BUViewModels.Add(buViewModel);
                                }

                                sbuViewModel.OBUViewModels.Add(obuViewModel);
                            }

                            companyViewModel.StrategicBusinessUnitViews.Add(sbuViewModel);
                        }

                        companyViewModels.Add(companyViewModel);
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error("Exception", e);
                return(null);
            }
            return(companyViewModels);
        }