public void DetailsHospitalShouldReturnCorrectViewModelTest() { var mockHospitalsService = new Mock <IHospitalsService>(); var mockUserManagerService = this.GetUserManagerMock(); var mockRecipientsService = new Mock <IRecipientsService>(); var mockBloodbanksService = new Mock <IBloodBanksService>(); var mockUsersService = new Mock <IUsersService>(); var viewModel = new AllHospitalBloodBagsViewModel(); var controller = new HospitalsController( mockHospitalsService.Object, mockUserManagerService.Object, mockRecipientsService.Object, mockBloodbanksService.Object, mockUsersService.Object); var result = controller.DetailsHospital("123", viewModel); Assert.IsType <RedirectToActionResult>(result); }
public IActionResult DetailsHospital(string id, AllHospitalBloodBagsViewModel viewModel) { viewModel.HospitalInfo = this.hospitalsService.GetHospitalDataById <HospitalInfoViewModel>(null, id); if (viewModel.HospitalInfo == null) { return(this.RedirectToAction("HttpStatusCodeHandler", "Error", this.NotFound())); } var allBags = this.bloodBanksService.GetHospitalBloodBagsById(id); foreach (var bag in allBags) { if ((int)bag.BloodGroup == 0) { if (bag.RhesusFactor == 0) { viewModel.ABPositiveQuantity += bag.Quantity; viewModel.ABPositiveQuantity = viewModel.ABPositiveQuantity > 10000 ? 10000 : viewModel.ABPositiveQuantity; } else { viewModel.ABNegativeQuantity += bag.Quantity; viewModel.ABNegativeQuantity = viewModel.ABNegativeQuantity > 10000 ? 10000 : viewModel.ABNegativeQuantity; } } else if ((int)bag.BloodGroup == 1) { if (bag.RhesusFactor == 0) { viewModel.APositiveQuantity += bag.Quantity; viewModel.APositiveQuantity = viewModel.APositiveQuantity > 10000 ? 10000 : viewModel.APositiveQuantity; } else { viewModel.ANegativeQuantity += bag.Quantity; viewModel.ANegativeQuantity = viewModel.ANegativeQuantity > 10000 ? 10000 : viewModel.ANegativeQuantity; } } else if ((int)bag.BloodGroup == 2) { if (bag.RhesusFactor == 0) { viewModel.BPositiveQuantity += bag.Quantity; viewModel.BPositiveQuantity = viewModel.BPositiveQuantity > 10000 ? 10000 : viewModel.BPositiveQuantity; } else { viewModel.BNegativeQuantity += bag.Quantity; viewModel.BNegativeQuantity = viewModel.BNegativeQuantity > 10000 ? 10000 : viewModel.BNegativeQuantity; } } else if ((int)bag.BloodGroup == 3) { if (bag.RhesusFactor == 0) { viewModel.ZeroPositiveQuantity += bag.Quantity; viewModel.ZeroPositiveQuantity = viewModel.ZeroPositiveQuantity > 10000 ? 10000 : viewModel.ZeroPositiveQuantity; } else { viewModel.ZeroNegativeQuantity += bag.Quantity; viewModel.ZeroNegativeQuantity = viewModel.ZeroNegativeQuantity > 10000 ? 10000 : viewModel.ZeroNegativeQuantity; } } } return(this.View(viewModel)); }