예제 #1
0
        public ActionResult Login(LoginModel model)
        {
            Admin admin = null;

            if (ModelState.IsValid)
            {
                using (BetterHelpDbEntities db = new BetterHelpDbEntities())
                {
                    admin = db.Admins.FirstOrDefault(a => a.Name == model.Name && a.Password == model.Password);
                }

                if (admin != null)
                {
                    try
                    {
                        FormsAuthentication.SetAuthCookie(model.Name, true);
                    }
                    catch (NullReferenceException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ViewBag.adminName = model.Name;
                    return(RedirectToAction("Index", "Admin"));
                }
                else
                {
                    ModelState.AddModelError("", "Пользователя с таким логином и паролем нет");
                }
            }

            return(View(model));
        }
예제 #2
0
        public void TestMethod1()
        {
            var h  = new HomeController();
            var db = new BetterHelpDbEntities();
            var ph = new Philanthropist {
                Amount = 100, FundId = 1, Id = 10, Name = "Андрей", Message = ""
            };

            var result = h.Donate(ph);



            Assert.IsTrue(result is ViewResult);
        }
예제 #3
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"));
        }
예제 #4
0
 public HomeController()
 {
     db = new BetterHelpDbEntities();
 }