public IActionResult Save(BranchIndexViewModel model) { var UserId = HttpContext.Session.GetString("UserId"); if (ModelState.IsValid) { var branch = new Branch { Id = model.Id, Description = model.Description, Company = _Branch.GetCompanyById(int.Parse(model.CompanyId)) }; if (model.Id.ToString().Equals("0")) { branch.CreatedBy = UserId; branch.CreationDate = DateTime.Now; _Branch.Add(branch); } else { branch.ModifiedBy = UserId; branch.ModifiedDate = DateTime.Now; _Branch.Update(branch); } return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", model)); } }
public IActionResult Index() { IEnumerable <Branch> list = _branchDataService.GetAll(); BranchIndexViewModel vm = new BranchIndexViewModel { Total = list.Count(), Branches = list }; return(View(vm)); }
public IActionResult Index() { var branches = _branch.GetAll().Select(x => new BranchDetailViewModel() { Id = x.Id, Name = x.Name, IsOpen = _branch.IsBranchOpen(x.Id), NumberOfAssets = _branch.GetAssets(x.Id).Count(), NumberOfPatrons = _branch.GetPatrons(x.Id).Count() }); var model = new BranchIndexViewModel() { Branches = branches }; return(View(model)); }
public IActionResult Index() { var result = _Branch.Branches().Select ( a => new BranchViewModel { Id = a.Id, Description = a.Description, Company = a.Company.Description } ).ToList(); var model = new BranchIndexViewModel { Branches = result, Companies = this.CompanyList() }; return(View(model)); }
public IActionResult Index() { var branchModels = _branchService.GetAll() .Select(br => new BranchDetailViewModel { Id = br.Id, BranchName = br.Name, NumberOfAssets = _branchService.GetAssetCount(br.Id), NumberOfPatrons = _branchService.GetPatronCount(br.Id), IsOpen = _branchService.IsBranchOpen(br.Id) }).ToList(); var model = new BranchIndexViewModel { Branches = branchModels }; return(View(model)); }
public IActionResult Index() { var branches = _branch.GetAll().Select(x => new BranchDetailViewModel() { Id = x.Id, Name = x.Name, IsOpen = _branch.IsBranchOpen(x.Id), //Asynchronous operations used in a blocking manner below NumberOfAssets = _branch.GetAssetsAsync(x.Id).Result.Count(), NumberOfPatrons = _branch.GetPatronsAsync(x.Id).Result.Count() }); var model = new BranchIndexViewModel() { Branches = branches }; return(View(model)); }