コード例 #1
0
        public ActionResult CreateDonatingForm(DonatingForm donatingForm)
        {
            int     age          = donatingForm.age;
            int     weight       = donatingForm.weight;
            int     pulse        = donatingForm.pulse;
            Boolean pregnancy    = donatingForm.womanProblems;
            Boolean drinking     = donatingForm.drink;
            Boolean intervention = donatingForm.intervention;
            Boolean affections   = donatingForm.affections;

            var donorTransactions = from row in db.donorTransactions.ToArray()
                                    where row.cnpDonor == donatingForm.cnp
                                    select row.donationDate;
            int   idCenter = donatingForm.idCenter;
            Donor donor1   = db.Donors.Find(donatingForm.cnp);

            donor1.idCenter = donatingForm.idCenter;

            db.Entry(donor1).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            if (donorTransactions.ToList().Count > 0)
            {
                if (donorTransactions.Last().HasValue)
                {
                    var lastTransaction = donorTransactions.Last() ?? DateTime.Now.Date;

                    var      today = DateTime.Now.Date;
                    TimeSpan daysBetweenDonations = today.Subtract(value: lastTransaction.Date);

                    if (daysBetweenDonations.Days <= 90)
                    {
                        var nextPossibleDate = lastTransaction.AddDays(90);
                        TempData["ConditionsNotMet"] = "Sorry, the minimum period of time between two donations is 90 days! The next date you can donate is: " + nextPossibleDate.Date + ".";
                        return(RedirectToAction("CreateDonatingForm", "DonatingForm"));
                    }
                }
            }

            if (age >= 18 && age <= 60 && weight >= 50 && pulse >= 60 && pulse <= 100 && !pregnancy && !drinking && !intervention && !affections)
            {
                donorTransaction d = new donorTransaction();
                d.cnpDonor = donatingForm.cnp;
                d.idCenter = donatingForm.idCenter;
                d.status   = "Prelevare";
                Donor donor = db.Donors.Find(donatingForm.cnp);
                donor.idCenter = donatingForm.idCenter;
                d.donationDate = DateTime.Now.Date;
                db.donorTransactions.Add(d);
                donationCenter center = db.donationCenters.Find(donatingForm.idCenter);
                db.SaveChanges();
                int idTransaction = db.donorTransactions.Where(a => a.cnpDonor == donatingForm.cnp).FirstOrDefault().id;
                TempData["Success"] = "Your request for donating blood has been submitted! The id of your transaction is " + idTransaction +
                                      ". < br /> Before donating, you can drink a coffee or a tea. You can also eat a light breakfast." +
                                      "< br /> Don't smoke before and after the donation for at least one hour!" +
                                      "< br /> Come to donate fresh, not tired!" +
                                      " < br /> We're waiting for you tomorrow between 7:00 and 11:00 at " + center.name;
                return(RedirectToAction("Index", "Home"));
            }
            TempData["ConditionsNotMet"] = "Sorry, the conditions to donate cannot be applied in your case!";
            return(RedirectToAction("CreateDonatingForm", "DonatingForm"));
        }
コード例 #2
0
        public ActionResult DonorTransactionEdit(int id, donorTransaction transaction)
        {
            try
            {
                if (transaction.status == "Acceptat")
                {
                    transaction.analysisStatus = "Pozitive";
                }
                else
                {
                    if (transaction.status == "Rebutat")
                    {
                        transaction.analysisStatus = "Negative";
                    }
                }

                if (transaction.status == "Acceptat")
                {
                    Donor d = db.Donors.Find(transaction.cnpDonor);
                    if (d.idBlood != null)
                    {
                        int           idBlood  = (int)d.idBlood;
                        int           idCenter = (int)transaction.idCenter;
                        bloodResource tt       = new bloodResource();
                        foreach (bloodResource t in db.bloodResources.ToList())
                        {
                            if (t.idBlood == idBlood && t.idCenter == idCenter)
                            {
                                tt = t;
                            }
                        }

                        tt.quantity        = tt.quantity + 500;
                        db.Entry(tt).State = System.Data.Entity.EntityState.Modified;

                        List <Transaction> transactionsListHigh   = new List <Transaction>();
                        List <Transaction> transactionsListMedium = new List <Transaction>();
                        List <Transaction> transactionsListLow    = new List <Transaction>();
                        foreach (Transaction t in db.Transactions.ToList())
                        {
                            if (t.idBlood == idBlood && t.idCenter == idCenter)
                            {
                                if (t.severity == "High")
                                {
                                    transactionsListHigh.Add(t);
                                }
                                if (t.severity == "Medium")
                                {
                                    transactionsListMedium.Add(t);
                                }
                                if (t.severity == "Low")
                                {
                                    transactionsListLow.Add(t);
                                }
                            }
                        }

                        foreach (Transaction t in transactionsListHigh)
                        {
                            if (t.status == "Prelevare")
                            {
                                if (t.quantity <= tt.quantity)
                                {
                                    t.status           = "Pregatire";
                                    db.Entry(t).State  = System.Data.Entity.EntityState.Modified;
                                    tt.quantity        = tt.quantity - t.quantity;
                                    db.Entry(tt).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                        }

                        foreach (Transaction t in transactionsListMedium)
                        {
                            if (t.status == "Prelevare")
                            {
                                if (t.quantity <= tt.quantity)
                                {
                                    t.status           = "Pregatire";
                                    db.Entry(t).State  = System.Data.Entity.EntityState.Modified;
                                    tt.quantity        = tt.quantity - t.quantity;
                                    db.Entry(tt).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                        }

                        foreach (Transaction t in transactionsListLow)
                        {
                            if (t.status == "Prelevare")
                            {
                                if (t.quantity <= tt.quantity)
                                {
                                    t.status           = "Pregatire";
                                    db.Entry(t).State  = System.Data.Entity.EntityState.Modified;
                                    tt.quantity        = tt.quantity - t.quantity;
                                    db.Entry(tt).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                        }
                    }
                }
                db.Entry(transaction).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                TempData["Success"] = "Donor transaction successfully updated!";
                return(RedirectToAction("DonorTransactionIndex"));
            }
            catch
            {
                return(View());
            }
        }