Exemplo n.º 1
0
        public void Field(string record, string size)
        {
            int idPlayer = db.Players.FirstOrDefault(p => p.Login == User.Identity.Name).Id;

            if (Convert.ToInt32(record) != 0)
            {
                db.Records.Add(new Record {
                    Player_Id = idPlayer, Size_field = Convert.ToInt32(size), Step_count = Convert.ToInt32(record)
                });
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Password != model.Password2)
                {
                    ViewBag.message = "Пароли не совпадают!";
                    ModelState.AddModelError("", "Пароли не совпадают!");
                    return(View(model));
                }
                Player player = null;
                using (DbFifteenContext db = new DbFifteenContext())
                {
                    player = db.Players.FirstOrDefault(u => u.Login == model.Login);
                }
                if (player == null)
                {
                    // создаем нового пользователя
                    using (DbFifteenContext db = new DbFifteenContext())
                    {
                        db.Players.Add(new Player {
                            Login = model.Login, Password = model.Password
                        });
                        db.SaveChanges();

                        player = db.Players.Where(u => u.Login == model.Login && u.Password == model.Password).FirstOrDefault();
                    }
                    // если пользователь удачно добавлен в бд
                    if (player != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Login, true);
                        ViewBag.Login = model.Login;
                        return(RedirectToAction("Menu", "Home"));
                    }
                }
                else
                {
                    ViewBag.message   = "Вы уже зарегестрированы!";
                    ViewBag.ThisLogin = Convert.ToString(model.Login);
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }
            return(View(model));
        }