public IActionResult Add(MedicineDemand meds) { // string s = meds.Medicine + meds.Demand.ToString(); try { if (meds == null) { return(RedirectToAction("Index", "DemandSupply")); } Demands newdemand = new Demands() { Medicine = meds.Medicine, Demand = meds.Demand }; int res = repo.AddDemand(newdemand); if (res > 0) { return(RedirectToAction("AddSupply", newdemand)); } return(RedirectToAction("Index", "DemandSupply")); } catch (Exception e) { ViewBag.Message = "Exception Encountered : " + e.Message; return(View("~/Views/Shared/ExceptionAndError.cshtml")); } }
/// <summary> /// This is the function where we get the medicinestock(Called from MedicineRepo) and /// perform some functionalities to fetch the numberoftablets of a particular medicine /// and check what should be the supplycount(i.e how many medicines can be supplied to user). /// Try and catch blocks are handled accordingly. /// </summary> /// <param name="demand"></param> /// <returns>MedicineSupply or null value depending on the type of demand</returns> public MedicineSupply GetSupply(MedicineDemand demand, string token) { IEnumerable <MedicineStock> medicinestock = _repocontext.GetSupply(token); medicinestock = from m in medicinestock where m.Name == demand.MedicineName select m; MedicineStock medicine = medicinestock.FirstOrDefault(); try { if (medicine != null) { int medicinecount = ((medicine.numberOfTabletsInStock) / (MedicineSupplyRepo.pharmacies.Count())); MedicineSupply medicinesupply = new MedicineSupply(); medicinesupply.MedicineName = medicine.Name; medicinesupply.DemandCount = demand.DemandCount; medicinesupply.SupplyCount = medicinecount; return(medicinesupply); } else { _log4net.Error("MedicineName not found in medicinestock " + nameof(MedicineSupplyProvider)); return(null); } } catch (Exception e) { _log4net.Error(e.Message + " from " + nameof(MedicineSupplyProvider)); throw e; } }
public async Task MedicineSupply_ServiceLayer_InValidDemandCount_NullOutput() { MedicineDemand demandOfSupplier = new MedicineDemand() { Medicine = "Aspirin", Demand = 0 }; MedicineSupplyService supplyService = new MedicineSupplyService(supplyRepo.Object); List <PharmacyMedicineSupply> serviceSupplyList = await supplyService.MedcineSupply(demandOfSupplier.Medicine, demandOfSupplier.Demand); Assert.IsNull(serviceSupplyList); }
public async Task GetSupplies_RepositoryLayer_InValidMedicineName_Fail() { MedicineDemand demandOfSupplier = new MedicineDemand() { Medicine = "abc", Demand = 100 }; ISupply repo = supplyRepo.Object; var result = await repo.GetSupplies(demandOfSupplier.Medicine, demandOfSupplier.Demand); Assert.IsNull(result); }
public async Task GetSupplies_RepositoryLayer_ValidInput_Pass() { MedicineDemand demandOfSupplier = new MedicineDemand() { Medicine = "Aspirin", Demand = 100 }; ISupply repo = supplyRepo.Object; var result = await repo.GetSupplies(demandOfSupplier.Medicine, demandOfSupplier.Demand); Assert.IsNotNull(result); }
public void GetSupplies_InValidInput_BadRequest() { MedicineDemand medicineDemand = new MedicineDemand() { Medicine = "Aspirin", Demand = 0 }; supplyService.Setup(s => s.MedcineSupply(medicineDemand.Medicine, medicineDemand.Demand)).ReturnsAsync(supplyList); var controller = new MedicineSupplyController(supplyService.Object, mapper.Object); var data = controller.GetSupplies(medicineDemand.Medicine, medicineDemand.Demand).Result; var s = data as BadRequestObjectResult; Assert.AreEqual(400, s.StatusCode); }
public IActionResult Add(MedicineDemand meds) { // string s = meds.Medicine + meds.Demand.ToString(); Demands newdemand = new Demands() { Medicine = meds.Medicine, Demand = meds.Demand }; int res = repo.AddDemand(newdemand); if (res > 0) { return(RedirectToAction("AddSupply", newdemand)); } return(RedirectToAction("Index", "Home")); }
public IActionResult GetSupply([FromBody] MedicineDemand demand) { if (demand.MedicineName == null && demand.DemandCount <= 0) { _log4net.Error("Null parameters passed from " + nameof(MedicineSupplyController)); return(BadRequest("Please enter atleast some MedicineName and DemandCount")); } try { if (demand.DemandCount > 0) { string token; MedicineSupply medicinesupply; if (string.IsNullOrEmpty(HttpContext.Request.Headers["Authorization"])) { token = ""; } else { token = HttpContext.Request.Headers["Authorization"].FirstOrDefault().Split(" ")[1]; } medicinesupply = _providercontext.GetSupply(demand, token); if (medicinesupply != null) { _log4net.Info("Medicine successfully accessed from Medicine Stock from " + nameof(MedicineSupplyController)); return(Ok(medicinesupply)); } else { _log4net.Error("MedicineName not found in MedicineStock " + nameof(MedicineSupplyController)); return(NotFound("Your entered medicine name does not exist in our MedicineStock")); } } else { _log4net.Error("DemandCount is 0 or negative from " + nameof(MedicineSupplyController)); return(BadRequest("Invalid DemandCount")); } } catch (Exception) { _log4net.Error("Internal server error " + nameof(MedicineSupplyController)); return(StatusCode(500)); } }
public void Setup() { supplyList = supplyList = new List <PharmacyMedicineSupply>() { new PharmacyMedicineSupply { MedicineName = "Aspirin", PharmacyName = "Apollo Pharmacy", SupplyCount = 50 }, new PharmacyMedicineSupply { MedicineName = "Aspirin", PharmacyName = "Max Pharmacy", SupplyCount = 50 } }; medicineDemand = new MedicineDemand() { Medicine = "Aspirin", Demand = 100 }; supplyRepo = new Mock <ISupply>(); supplyRepo.Setup(s => s.GetSupplies(medicineDemand.Medicine, medicineDemand.Demand)).ReturnsAsync(supplyList); }
public void GetSupplies_ValidInput_OkResult() { try { MedicineDemand medicineDemand = new MedicineDemand() { Medicine = "Aspirin", Demand = 100 }; supplyService.Setup(s => s.MedcineSupply(medicineDemand.Medicine, medicineDemand.Demand)).ReturnsAsync(supplyList); var controller = new MedicineSupplyController(supplyService.Object, mapper.Object); var data = controller.GetSupplies(medicineDemand.Medicine, medicineDemand.Demand).Result; var res = data as OkObjectResult; Assert.AreEqual(200, res.StatusCode); } catch (Exception e) { Assert.AreEqual("Object reference not set to an instance of an object.", e.Message); } }
public List <MedicineDemand> GetDemand(List <MedicineStock> stocks) { try { List <MedicineDemand> demands = new List <MedicineDemand>(); foreach (var stock in stocks) { MedicineDemand demand = new MedicineDemand() { MedicineName = stock.Name, Count = 0 }; demands.Add(demand); } return(demands); } catch (Exception) { throw; } }
public List <MedicineDemand> GetDemand(List <MedicineStock> stocks) { try { List <MedicineDemand> demands = new List <MedicineDemand>(); foreach (var stock in stocks) { MedicineDemand demand = new MedicineDemand() { MedicineName = stock.Name, Count = stock.NumberOfTabletsInStock }; demands.Add(demand); } _log.Info("stock converted to demand"); return(demands); } catch (Exception e) { _log.Error("Error while converting Stock to Demand in DemandProvider" + e.Message); throw; } }