public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = null;
                using (SkladContext db = new SkladContext())
                {
                    user = db.Users.FirstOrDefault(u => u.Login == model.Login);
                }
                if (user == null)
                {
                    using (SkladContext db = new SkladContext())
                    {
                        db.Users.Add(new User {
                            Login = model.Login, Password = model.Password, Role = "manager"
                        });
                        db.SaveChanges();

                        user = db.Users.FirstOrDefault(u => u.Login == model.Login && u.Password == model.Password);
                    }
                    if (user != null)
                    {
                        //FormsAuthentication.SetAuthCookie(model.Login, true);
                        return(RedirectToAction("Users", "Admin"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином или почтой уже существует");
                }
            }

            return(View(model));
        }
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                User user = null;
                using (SkladContext db = new SkladContext())
                {
                    user = db.Users.FirstOrDefault(u => u.Login == model.Login && u.Password == model.Password);
                }
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(user.Login, true);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Пользователя с таким логином и паролем нет");
                }
            }

            return(View(model));
        }
Exemple #3
0
 public SaleService(SkladContext db)
 {
     _db = db;
 }
Exemple #4
0
 public AdminController()
 {
     _db = new SkladContext();
     _statisticService = new StatisticService(_db);
     _saleService      = new SaleService(_db);
 }
Exemple #5
0
 public StatisticService(SkladContext db)
 {
     _db = db;
 }