public ActionResult Add(LoginModel userInfo)
        {
            if (ModelState.IsValid)
            {
                using (Entities db = new Entities())
                {
                    IQueryable<User> users = db.User
                        .Where(user => user.Email.Equals(userInfo.Email));

                    if (users.AsEnumerable().Count() == 0)
                    {
                        ModelState.AddModelError("", "Данные введены не верно");

                        ViewBag.Close = false;

                        return PartialView("Create", userInfo);
                    }
                    else
                    {
                        foreach (User curuser in users)
                        {
                            Security crypto = new Security();

                            bool isVerify = crypto.VerifyMd5Hash(MD5.Create(), userInfo.Password, curuser.Password);

                            if (isVerify)
                            {
                                Session["IsAuthenticated"] = "true";

                                Session["UserSurname"] = curuser.Surname;

                                Session["UserFirstName"] = curuser.FirstName;

                                string rol = curuser.Role1.RoleName;

                                Session["UserRole"] = rol;

                                Session["UserEmail"] = curuser.Email;
                            }
                            else
                            {
                                ModelState.AddModelError("", "Данные введены не верно");

                                ViewBag.Close = false;

                                return PartialView("Create", userInfo);
                            }
                        }

                        ViewBag.Close = true;

                        return PartialView("Create", userInfo);
                    }
                }
            }

            return PartialView("Create", userInfo);
        }
        public ActionResult Add(RegistrationModel userInfo)
        {
            Entities db = new Entities();

            IQueryable<User> existUser = db.User.Where(user => user.Email.Equals(userInfo.Email));

            if (ModelState.IsValid && existUser.Count() == 0)
            {
                User user = new User();

                user.FirstName = userInfo.FirstName;

                user.Surname = userInfo.Surname;

                user.Email = userInfo.Email;

                using (MD5 md5Hash = MD5.Create())
                {
                    Security crypto = new Security();

                    user.Password = crypto.GetMd5Hash(md5Hash, userInfo.Password);
                }

                user.Role1 = db.Role.Where(role => role.RoleName.Equals("Client")).First();

                db.User.Add(user);

                db.SaveChanges();

                Session["IsAuthenticated"] = "true";

                Session["UserSurname"] = user.Surname;

                Session["UserFirstName"] = user.FirstName;

                string rol = user.Role1.RoleName;

                Session["UserRole"] = rol;

                Session["UserEmail"] = user.Email;

                ViewBag.Close = true;

                return PartialView("Create", userInfo);
            }

            ViewBag.Close = false;

            return PartialView("Create", userInfo);
        }