/// <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;
            }
        }
Exemplo n.º 2
0
    public static void LoadData()
    {
        SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("AbnormalDruggery");

        while (reader.Read())
        {
            MedicineSupply ms = new MedicineSupply();
            ms.id      = Convert.ToInt32(reader.GetString(reader.GetOrdinal("id")));
            ms.protoId = Convert.ToInt32(reader.GetString(reader.GetOrdinal("prototypeitem_id")));
            ms.count   = Convert.ToInt32(reader.GetString(reader.GetOrdinal("count")));
            ms.rounds  = Convert.ToSingle(reader.GetString(reader.GetOrdinal("rounds")));

            medicineData.Add(ms);
        }
    }