Exemplo n.º 1
0
        public ActionResult Edit(int id, string title, string goalAmount, string collectedAmount, string info, HttpPostedFileBase logo)
        {
            string fileName = logo != null?System.IO.Path.GetFileName(logo.FileName) : null;

            if (!String.IsNullOrEmpty(fileName))
            {
                logo.SaveAs(Server.MapPath("~/images/" + fileName));
            }

            Fund fund = db.Funds.Find(id);

            fund.Title           = title;
            fund.GoalAmount      = Convert.ToInt32(goalAmount);
            fund.CollectedAmount = String.IsNullOrEmpty(collectedAmount) ? 0 : Convert.ToInt32(collectedAmount);
            fund.Info            = info;

            if (!String.IsNullOrEmpty(fileName))
            {
                logo.SaveAs(Server.MapPath("~/images/" + fileName));
                fund.LogoName = fileName;
            }

            db.Entry(fund).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "FundId,Title,GoalAmount,CollectedAmount,Info,LogoName")] Fund fund)
        {
            if (ModelState.IsValid)
            {
                db.Funds.Add(fund);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fund));
        }
        public ActionResult Create([Bind(Include = "Id,FundId,Name,Amount,Message")] Philanthropist philanthropist)
        {
            if (ModelState.IsValid)
            {
                db.Philanthropists.Add(philanthropist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.FundId = new SelectList(db.Funds, "FundId", "Title", philanthropist.FundId);
            return(View(philanthropist));
        }
Exemplo n.º 4
0
        public ActionResult Donate([Bind(Include = "Id,FundId,Name,Amount,Message")] Philanthropist philanthropist)
        {
            if (ModelState.IsValid)
            {
                var fundCollectedAmount = db.Funds.Find(philanthropist.FundId);
                fundCollectedAmount.CollectedAmount = fundCollectedAmount.CollectedAmount + philanthropist.Amount;
                try
                {
                    db.Philanthropists.Add(philanthropist);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                db.SaveChanges();
                return(View("ThankYouPage"));
            }

            return(RedirectToAction("Donate", "Home", new{ fundId = philanthropist.FundId }));
        }
Exemplo n.º 5
0
        public ActionResult Create(string title, string goalAmount, string collectedAmount, string info, HttpPostedFileBase logo)
        {
            string fileName = System.IO.Path.GetFileName(logo.FileName);

            logo.SaveAs(Server.MapPath("~/images/" + fileName));

            using (BetterHelpDbEntities db = new BetterHelpDbEntities())
            {
                Fund fund = new Fund
                {
                    FundId          = db.Funds.Select(x => x.FundId).Max() + 1,
                    Title           = title,
                    GoalAmount      = Convert.ToInt32(goalAmount),
                    CollectedAmount = String.IsNullOrEmpty(collectedAmount) ? 0 : Convert.ToInt32(collectedAmount),
                    Info            = info,
                    LogoName        = fileName
                };
                db.Funds.Add(fund);
                db.SaveChanges();
            }
            ViewData["isSuccess"] = true;
            return(RedirectToAction("Index", "Admin"));
        }