public static int EditDonation(Donation ad)
 {
     int upt = 0;
     try
     {
         upt = DataAccessLayer.DonationDA.EditDonation(ad);
     }
     catch (Exception)
     {
         return 0;
     }
     return upt;
 }
        public static int AddDonation(Donation ad)
        {
            int ins = 0;
            try
            {
                ins = DataAccessLayer.DonationDA.AddDonation(ad);
            }
            catch (Exception)
            {
                return 0;
            }

            return ins;
        }
        public ActionResult DonateProcess(FormCollection frm)
        {
            int kt = 0;
            try
            {
                int? cause = null;
                int? program = null;
                if (frm["ProgramId"] != null && frm["ProgramId"] != "")
                {
                    program = int.Parse(frm["ProgramId"]);
                }
                if (frm["CauseOfDonation"] != null && frm["CauseOfDonation"] != "")
                {
                    cause = int.Parse(frm["CauseOfDonation"]);
                }

                Donation dn = new Donation()
                {
                    FullNameDonator = frm["FullNameDonator"],
                    GenderDonator = frm["GenderDonator"],
                    EmailDonator = frm["EmailDonator"],
                    CauseId = cause,
                    ProgramId = program,
                    DateOfDonation= DateTime.Today.Date,
                    Amount=double.Parse(frm["Amount"]),
                    CreditType = frm["CreditType"],
                    CardNumber = frm["CardNumber"],
                };

                kt = DonationBusiness.AddDonation(dn);
            }
            catch
            {
                kt = 0;
            }

            if (kt > 0)
            {
                return RedirectToAction("Donate", "Donate", new { add = "success" });
            }
            else
            {
                return RedirectToAction("Donate", "Donate", new { add = "error" });
            }
        }
        private static List<Donation> AddDonationToList(DataTable dt)
        {
            List<Donation> ls = new List<Donation>();
            try
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string program = "";
                    Nullable<int> programId= null;
                    if ((dt.Rows[i]["ProgramId"].ToString()) != "")
                    {
                        programId = int.Parse(dt.Rows[i]["ProgramId"].ToString());
                        program = dt.Rows[i]["Name"].ToString();
                    }

                    Nullable<int> causeId = null;
                    string causeOfDonation = "";
                    if ((dt.Rows[i]["CauseId"].ToString()) != "")
                    {
                        causeId = int.Parse(dt.Rows[i]["CauseID"].ToString());
                        causeOfDonation = dt.Rows[i]["Description"].ToString();
                    }

                    Donation ad = new Donation()
                    {
                        Id = int.Parse(dt.Rows[i]["Id"].ToString()),
                        FullNameDonator = dt.Rows[i]["FullNameDonator"].ToString(),
                        EmailDonator = dt.Rows[i]["EmailDonator"].ToString(),
                        GenderDonator = dt.Rows[i]["GenderDonator"].ToString(),
                        CauseId= causeId,
                        CauseOfDonation = causeOfDonation,
                        ProgramId = programId,
                        Program = program,
                        DateOfDonation = DateTime.Parse(dt.Rows[i]["DateOfDonation"].ToString()),
                        Amount = double.Parse(dt.Rows[i]["Amount"].ToString()),
                        CreditType = dt.Rows[i]["CreditType"].ToString(),
                        CardNumber = dt.Rows[i]["CardNumber"].ToString(),
                        IsDeleted = int.Parse(dt.Rows[i]["IsDeleted"].ToString())
                    };

                    ls.Add(ad);

                }
            }
            catch (Exception)
            {
                return new List<Donation>();
            }
            return ls;
        }
        private static List<Donation> AddDonationToList2(DataTable dt,string flag)
        {
            List<Donation> ls = new List<Donation>();
            try
            {
                if (flag == "program")
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Donation ad = new Donation()
                        {
                            Program = dt.Rows[i]["Name"].ToString(),
                            ProgramId = int.Parse(dt.Rows[i]["Id"].ToString()),
                            TotalAmount = double.Parse(dt.Rows[i]["TotalAmount"].ToString()),
                            NumberOfDonation = int.Parse(dt.Rows[i]["NumberOfDonation"].ToString())
                        };

                        ls.Add(ad);

                    }
                }
                else
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Donation ad = new Donation()
                        {
                            CauseOfDonation = dt.Rows[i]["Description"].ToString(),
                            CauseId = int.Parse(dt.Rows[i]["Id"].ToString()),
                            TotalAmount = double.Parse(dt.Rows[i]["TotalAmount"].ToString()),
                            NumberOfDonation = int.Parse(dt.Rows[i]["NumberOfDonation"].ToString())
                        };

                        ls.Add(ad);

                    }
                }

            }
            catch (Exception)
            {
                return new List<Donation>();
            }
            return ls;
        }
Esempio n. 6
0
 public void Update(Donation item)
 {
     db.Donations.UpdateById(item);
 }
Esempio n. 7
0
 public Donation Insert(Donation donation)
 {
     return db.Donations.Insert(donation);
 }