Example #1
0
        public ActionResult SBUUpdate([DataSourceRequest] DataSourceRequest dataSourceRequest, StrategicBusinessUnitViewModel strategicBusinessUnitViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (ASJDE context = new ASJDE())
                    {
                        StrategicBusinessUnit strategicBusinessUnit = (from s in context.StrategicBusinessUnits
                                                                       where s.ID == strategicBusinessUnitViewModel.ID
                                                                       select s).FirstOrDefault();

                        if (strategicBusinessUnit != null)
                        {
                            strategicBusinessUnit.EntityID  = strategicBusinessUnitViewModel.EntityID;
                            strategicBusinessUnit.CompanyID = strategicBusinessUnitViewModel.CompanyID;

                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error("Exception", e);
            }
            return(Json(new[] { strategicBusinessUnitViewModel }.ToDataSourceResult(dataSourceRequest, ModelState)));
        }
Example #2
0
        public ActionResult SBUCreate([DataSourceRequest] DataSourceRequest request, StrategicBusinessUnitViewModel strategicBusinessUnitViewModel)
        {
            try
            {
                if (strategicBusinessUnitViewModel != null && ModelState.IsValid)
                {
                    using (ASJDE context = new ASJDE())
                    {
                        StrategicBusinessUnit strategicBusinessUnit = new StrategicBusinessUnit
                        {
                            CompanyID = strategicBusinessUnitViewModel.CompanyID,
                            EntityID  = strategicBusinessUnitViewModel.EntityID
                        };

                        context.StrategicBusinessUnits.Add(strategicBusinessUnit);
                        context.SaveChanges();
                        strategicBusinessUnitViewModel.ID = strategicBusinessUnit.ID;
                    }
                }

                return(Json(new[] { strategicBusinessUnitViewModel }.ToDataSourceResult(request, ModelState)));
            }
            catch (Exception e)
            {
                logger.Error("Exception", e);
                return(null);
            }
        }
        public async Task <StrategicBusinessUnit> UpdateStrategyBusinessUnit(StrategicBusinessUnit sbu)
        {
            var updatedEntity = _context.StrategicBusinessUnits.Update(sbu);

            if (await SaveChanges())
            {
                return(updatedEntity.Entity);
            }
            return(null);
        }
        public async Task <StrategicBusinessUnit> SaveStrategyBusinessUnit(StrategicBusinessUnit sbu)
        {
            var savedEntity = await _context.StrategicBusinessUnits.AddAsync(sbu);

            if (await SaveChanges())
            {
                return(savedEntity.Entity);
            }
            return(null);
        }
Example #5
0
        public ActionResult SBUDestroy([DataSourceRequest] DataSourceRequest request, StrategicBusinessUnitViewModel strategicBusinessUnitViewModel)
        {
            try
            {
                if (strategicBusinessUnitViewModel != null)
                {
                    using (ASJDE context = new ASJDE())
                    {
                        StrategicBusinessUnit strategicBusinessUnit = (from s in context.StrategicBusinessUnits
                                                                       where s.ID == strategicBusinessUnitViewModel.ID
                                                                       select s).FirstOrDefault();
                        context.StrategicBusinessUnits.Remove(strategicBusinessUnit);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error("Exception", e);
            }

            return(Json(ModelState.ToDataSourceResult()));
        }
Example #6
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);
        }
 public async Task <bool> DeleteStrategyBusinessUnit(StrategicBusinessUnit sbu)
 {
     _context.StrategicBusinessUnits.Remove(sbu);
     return(await SaveChanges());
 }
Example #8
0
        public ActionResult SBUCreate([DataSourceRequest] DataSourceRequest request, StrategicBusinessUnitViewModel strategicBusinessUnitViewModel)
        {
            try
            {
                if (strategicBusinessUnitViewModel != null && ModelState.IsValid)
                {
                    using (ASJDE context = new ASJDE())
                    {

                        StrategicBusinessUnit strategicBusinessUnit = new StrategicBusinessUnit
                            {
                                CompanyID = strategicBusinessUnitViewModel.CompanyID,
                                EntityID = strategicBusinessUnitViewModel.EntityID
                            };

                        context.StrategicBusinessUnits.Add(strategicBusinessUnit);
                        context.SaveChanges();
                        strategicBusinessUnitViewModel.ID = strategicBusinessUnit.ID;

                    }
                }

                return Json(new[] { strategicBusinessUnitViewModel }.ToDataSourceResult(request, ModelState));

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