public ActionResult Create([Bind(Include = "VaccineUseId,vaccineID,lotNumber,expdate,patientID,LinjectionSite,RinjectionSite,LIntradermal,RIntradermal,LIntramuscular,RIntramuscular,lsub,rsub,lnasal,rnasal,quantity,VaccineUseDate")] VaccineUse vaccineuse)
        {
            if (ModelState.IsValid)
            {
                db.VaccineUses.Add(vaccineuse);
                db.SaveChanges();

                //Decrease amount from quantity
                VaccineDBContext VaccineDB = new VaccineDBContext();
                Vaccine          Vac       = new Vaccine();

                string vaccineID  = vaccineuse.vaccineID;
                string lot        = vaccineuse.lotNumber;
                int    decreaseby = vaccineuse.quantity;

                var query =
                    from VDB in VaccineDB.Vaccines
                    where VDB.lotNumber == lot && VDB.vaccineID == vaccineID
                    select VDB;

                foreach (Vaccine vdb in query)
                {
                    int currentvaccinequantity = vdb.numofDoses;
                    int newvaccinetotal        = currentvaccinequantity - decreaseby;
                    vdb.numofDoses = newvaccinetotal;

                    if (newvaccinetotal <= vdb.inventoryWarning)
                    {
                        dynamic email = new Email("Warning");
                        email.To = "*****@*****.**";
                        email.Send();
                    }
                }

                try
                {
                    VaccineDB.SaveChanges();

                    Console.WriteLine("Vaccine Amount Updated!");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                return(RedirectToAction("Index"));
            }

            return(View(vaccineuse));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "VaccineUseId,vaccineID,lotNumber,patientID,LinjectionSite,RinjectionSite,quantity,VaccineUseDate")] VaccineUse vaccineuse)
        {
            if (ModelState.IsValid)
            {
                db.VaccineUses.Add(vaccineuse);
                db.SaveChanges();

                //Decrease amount from quantity
                VaccineDBContext VaccineDB = new VaccineDBContext();
                Vaccine          Vac       = new Vaccine();

                string vaccineID  = vaccineuse.vaccineID;
                string lot        = vaccineuse.lotNumber;
                int    decreaseby = vaccineuse.quantity;

                var query =
                    from VDB in VaccineDB.Vaccines
                    where VDB.lotNumber == lot && VDB.vaccineID == vaccineID
                    select VDB;

                foreach (Vaccine vdb in query)
                {
                    int currentvaccinequantity = vdb.numofDoses;
                    int newvaccinetotal        = currentvaccinequantity - decreaseby;
                    vdb.numofDoses = newvaccinetotal;
                }

                try
                {
                    VaccineDB.SaveChanges();
                    Console.WriteLine("Vaccine Amount Updated!");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                return(RedirectToAction("Index"));
            }

            return(View(vaccineuse));
        }