public ActionResult OBUDestroy([DataSourceRequest] DataSourceRequest request, OperationalBusinessUnitViewModel operationalBusinessUnitViewModel) { try { if (operationalBusinessUnitViewModel != null) { using (ASJDE context = new ASJDE()) { OperationalBusinessUnit operationalBusinessUnit = (from s in context.OperationalBusinessUnits where s.ID == operationalBusinessUnitViewModel.ID select s).FirstOrDefault(); context.OperationalBusinessUnits.Remove(operationalBusinessUnit); context.SaveChanges(); } } } catch (Exception e) { logger.Error("Exception", e); } return(Json(ModelState.ToDataSourceResult())); }
public ActionResult OBUCreate([DataSourceRequest] DataSourceRequest request, OperationalBusinessUnitViewModel operationalBusinessUnitViewModel) { try { if (operationalBusinessUnitViewModel != null && ModelState.IsValid) { using (ASJDE context = new ASJDE()) { OperationalBusinessUnit operationalBusinessUnit = new OperationalBusinessUnit { StrategicBusinessUnitID = operationalBusinessUnitViewModel.StrategicBusinessUnitID, EntityID = operationalBusinessUnitViewModel.EntityID }; context.OperationalBusinessUnits.Add(operationalBusinessUnit); context.SaveChanges(); operationalBusinessUnitViewModel.ID = operationalBusinessUnit.ID; } } return(Json(new[] { operationalBusinessUnitViewModel }.ToDataSourceResult(request, ModelState))); } catch (Exception e) { logger.Error("Exception", e); return(null); } }
public ActionResult OBUUpdate([DataSourceRequest] DataSourceRequest dataSourceRequest, OperationalBusinessUnitViewModel operationalBusinessUnitViewModel) { try { if (ModelState.IsValid) { using (ASJDE context = new ASJDE()) { OperationalBusinessUnit operationalBusinessUnit = (from s in context.OperationalBusinessUnits where s.ID == operationalBusinessUnitViewModel.ID select s).FirstOrDefault(); if (operationalBusinessUnit != null) { operationalBusinessUnit.EntityID = operationalBusinessUnitViewModel.EntityID; operationalBusinessUnit.StrategicBusinessUnitID = operationalBusinessUnitViewModel.StrategicBusinessUnitID; context.SaveChanges(); } } } } catch (Exception e) { logger.Error("Exception", e); } return(Json(new[] { operationalBusinessUnitViewModel }.ToDataSourceResult(dataSourceRequest, ModelState))); }
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 ActionResult OBUCreate([DataSourceRequest] DataSourceRequest request, OperationalBusinessUnitViewModel operationalBusinessUnitViewModel) { try { if (operationalBusinessUnitViewModel != null && ModelState.IsValid) { using (ASJDE context = new ASJDE()) { OperationalBusinessUnit operationalBusinessUnit = new OperationalBusinessUnit { StrategicBusinessUnitID = operationalBusinessUnitViewModel.StrategicBusinessUnitID, EntityID = operationalBusinessUnitViewModel.EntityID }; context.OperationalBusinessUnits.Add(operationalBusinessUnit); context.SaveChanges(); operationalBusinessUnitViewModel.ID = operationalBusinessUnit.ID; } } return Json(new[] { operationalBusinessUnitViewModel }.ToDataSourceResult(request, ModelState)); } catch (Exception e) { logger.Error("Exception", e); return null; } }