public object GetDonationRecipient(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Donation_Recipient objectDonationRecipient = new Donation_Recipient();
            dynamic            toReturn = new ExpandoObject();

            try
            {
                objectDonationRecipient = db.Donation_Recipient.Find(id);

                if (objectDonationRecipient == null)
                {
                    toReturn.Message = "Record Not Found";
                }
                else
                {
                    toReturn = objectDonationRecipient;
                }
            }
            catch (Exception error)
            {
                toReturn = "Something Went Wrong: " + error.Message;
            }

            return(toReturn);
        }
        public object getAddedDonation(string cell)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                Donation_Recipient donationRecipient = db.Donation_Recipient.Where(z => z.DrCell == cell).FirstOrDefault();
                Donation           donation          = db.Donations.Where(z => z.RecipientID == donationRecipient.RecipientID).ToList().LastOrDefault();
                //toReturn.Donation = searchDonationByID(donation.DonationID);
                //var donation = db.Donations.Include(z => z.Donation_Status).Include(z => z.Donation_Recipient).Include(z => z.Donated_Product).Where(z => z.DonationID == ID).FirstOrDefault();
                //var donationRecipient = db.Donation_Recipient.Where(x => x.RecipientID == donation.RecipientID).FirstOrDefault();

                if (donationRecipient != null)
                {
                    dynamic recipientDet = new ExpandoObject();
                    recipientDet.DrName      = donationRecipient.DrName;
                    recipientDet.DrSurname   = donationRecipient.DrSurname;
                    recipientDet.DrEmail     = donationRecipient.DrEmail;
                    recipientDet.DrCell      = donationRecipient.DrCell;
                    recipientDet.RecipientID = donationRecipient.RecipientID;

                    toReturn.recipient = recipientDet;

                    // toReturn = donations
                    if (donation != null)
                    {
                        dynamic don = new ExpandoObject();
                        don.DonationID       = donation.DonationID;
                        don.RecipientID      = donation.RecipientID;
                        don.DonAmount        = donation.DonAmount;
                        don.DonDate          = donation.DonDate;
                        don.DonDescription   = donation.DonDescription;
                        don.DonationStatusID = donation.DonationStatusID;
                        //don.DonStatus = donation.Donation_Status.DSDescription;
                        toReturn.donation   = don;
                        toReturn.donationID = donation.DonationID;
                    }
                }
            }
            catch (Exception)
            {
                toReturn.Message = "Failed to get donation";
            }

            return(toReturn);
        }
        public object AddDonationRecipient(Donation_Recipient newDonationRecipient)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                db.Donation_Recipient.Add(newDonationRecipient);
                db.SaveChanges();
                toReturn.Message = "Add Succsessful";
            }
            catch (Exception)
            {
                toReturn.Message = "Add UnSuccsessful";
            }

            return(toReturn);
        }
        public object UpdateDonationRecipient(Donation_Recipient donationRecipientUpdate)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Donation_Recipient objectDonationRecipient = new Donation_Recipient();
            dynamic            toReturn = new ExpandoObject();
            var id = donationRecipientUpdate.RecipientID;

            try
            {
                objectDonationRecipient = db.Donation_Recipient.Where(x => x.RecipientID == id).FirstOrDefault();
                if (objectDonationRecipient != null)
                {
                    objectDonationRecipient.DrName     = donationRecipientUpdate.DrName;
                    objectDonationRecipient.DrSurname  = donationRecipientUpdate.DrSurname;
                    objectDonationRecipient.DrCell     = donationRecipientUpdate.DrCell;
                    objectDonationRecipient.DrEmail    = donationRecipientUpdate.DrEmail;
                    objectDonationRecipient.DrStreetNr = donationRecipientUpdate.DrStreetNr;
                    objectDonationRecipient.DrStreet   = donationRecipientUpdate.DrStreet;
                    objectDonationRecipient.DrCode     = donationRecipientUpdate.DrCode;
                    objectDonationRecipient.DrArea     = donationRecipientUpdate.DrArea;

                    db.SaveChanges();

                    toReturn.Message = "Update Successfull";
                }
                else
                {
                    toReturn.Message = "Record Not Found";
                }
            }

            catch (Exception)
            {
                toReturn.Message = "Update UnSuccessfull";
            }
            return(toReturn);
        }
        public object DeleteDonationRecipient(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Donation_Recipient objectDonationRecipient = new Donation_Recipient();
            dynamic            toReturn = new ExpandoObject();

            try
            {
                objectDonationRecipient = db.Donation_Recipient.Find(id);

                if (objectDonationRecipient == null)
                {
                    toReturn.Message = "Record Not Found";
                }
                else
                {
                    List <Donation> donation = db.Donations.Where(x => x.Donation_Recipient.RecipientID == id).ToList();
                    if (donation.Count == 0)
                    {
                        db.Donation_Recipient.Remove(objectDonationRecipient);
                        db.SaveChanges();
                        toReturn.Message = "Delete Successful";
                    }
                    else
                    {
                        toReturn.Message = "Donation Recepient Delete Restricted";
                    }
                }
            }
            catch
            {
                toReturn = "Delete Unsuccesful";
            }

            return(toReturn);
        }