public IActionResult Detail(int?id) { if (id == null) { return(View("NoIdFound")); } var branch = _branch.GetBranchById((int)id); if (branch == null) { Response.StatusCode = 404; return(View("BranchNotFound", id)); } var model = new BranchDetailViewModel() { Id = branch.Id, Name = branch.Name, Address = branch.Address, Telephone = branch.Telephone, Description = branch.Description, OpenDate = branch.OpenDate.ToString("yyyy-MM-dd"), NumberOfAssets = _branch.GetAssets((int)id).Count(), NumberOfPatrons = _branch.GetPatrons((int)id).Count(), TotalAssetValue = _branch.GetAssets((int)id).Sum(x => x.Cost), ImageUrl = branch.ImageUrl, HoursOpen = _branch.GetBranchHours((int)id) }; return(View(model)); }
public async Task <BranchDetailViewModel> GetBranchDetail(Guid branchId) { try { var brach = await _unitOfWork.BranchRepository .GetById(branchId); var storers = await _unitOfWork.StorerRepository .Get(x => x.BranchId == branchId && x.Active); var storerViewModels = storers.Select(x => new StorerViewModel { StorerId = x.Id, StorerName = x.Description }); var result = new BranchDetailViewModel { BranchId = branchId, Address = brach.Address, BranchName = brach.BranchName, Phone = brach.Phone, Storers = storerViewModels }; return(result); } catch (Exception ex) { //Logger.CreateLog(Logger.Levels.ERROR, this, "GetAllArea(bool? isActive)", ex, "isActive=" + isActive + ", " + ex.Message); return(null); } }
public async Task <IHttpActionResult> Branch([FromBody] BranchDetailViewModel viewModel) { try { if (!ModelState.IsValid) { return(DataValidationError(GetErrorMessages(ModelState))); } var output = await _masterService.InsertBranch(viewModel); //var output = await _masterService.InsertBranch2(viewModel); if (output == false) { return(InternalServerErrorResult()); } var result = new ObjectResult { StatusCode = 201, Message = "Save data successfully", Result = output }; return(Ok(result)); } catch (Exception ex) { return(InternalServerErrorResult()); } }
public async Task <IActionResult> Edit(BranchDetailViewModel branchModel) { string fullAddress = branchModel.Address + " " + branchModel.Town; //TODO: make branch edit friendly error page if (!ModelState.IsValid) { this.TempData.AddFailureMessage(string.Format(FailureEditItemMessage, fullAddress)); return(this.RedirectToAction(nameof(Index))); //return this.BadRequest(); } await this.branchesService.EditAsync(branchModel.Id, branchModel.Town, branchModel.Address); this.TempData.AddSuccessMessage(string.Format(SuccessEditItemMessage, fullAddress)); return(this.RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit([FromRoute(Name = "id")] int branchId) { var branch = await this.branchesService.GetByIdAsync <BranchDetailViewModel> (branchId); if (branch == null) { return(this.BadRequest()); } var editBranch = new BranchDetailViewModel { Town = branch.Town, Address = branch.Address }; return(this.View(editBranch)); }
public async Task <bool> InsertBranch(BranchDetailViewModel viewModel) { try { var result = false; // insert branch var branch = new Branch { Id = Guid.NewGuid(), BranchName = viewModel.BranchName, Address = viewModel.Address, Active = true, Phone = viewModel.Phone }; _unitOfWork.BranchRepository.Insert(branch); // insert its storer var storers = viewModel.Storers; foreach (var storer in storers) { _unitOfWork.StorerRepository.Insert(new Storer { Id = Guid.NewGuid(), BranchId = branch.Id, Description = storer.StorerName, Active = true, AddDate = DateTime.Now, EditDate = DateTime.Now }); } // save data=>true/false result = await _unitOfWork.Save(); return(result); } catch (Exception ex) { //Logger.CreateLog(Logger.Levels.ERROR, this, "GetAllArea(bool? isActive)", ex, "isActive=" + isActive + ", " + ex.Message); return(false); } }
public IActionResult Detail(int id) { var branch = _branchServices.Get(id); var model = new BranchDetailViewModel { Id = branch.Id, Name = branch.Name, Address = branch.Address, Telephone = branch.Telephone, OpenDate = branch.OpenDate.ToString("yyyyy-MM-dd"), NumberOfAssets = _branchServices.GetAssets(branch.Id).Count(), NumberOfPatrons = _branchServices.GetPatrons(branch.Id).Count(), TotalAssetValue = _branchServices.GetAssets(id).Sum(x => x.Cost), ImageUrl = branch.ImageUrl, HoursOpen = _branchServices.GetBranchHours(id) }; return(View(model)); }
public IActionResult Detail(int id) { var branch = _branchService.Get(id); var model = new BranchDetailViewModel { BranchName = branch.Name, Description = branch.Description, Address = branch.Address, Telephone = branch.Telephone, BranchOpenedDate = branch.OpenDate.ToString("yyyy-MM-dd"), NumberOfPatrons = _branchService.GetPatronCount(id), NumberOfAssets = _branchService.GetAssetCount(id), TotalAssetValue = _branchService.GetAssetsValue(id), ImageUrl = branch.ImageUrl, HoursOpen = _branchService.GetBranchHours(id) }; return(View(model)); }