public string ProccessData(List<DataVote> data)
        {
            if (data != null && Session["IsVoted"] ==null)
            {
                List<Сandidate> candidates = new List<Сandidate>();
                using (var db = new DbRepository(new dbname123Entities()))
                {

                    candidates = db.GetСandidate().ToList();

                    foreach (var el in candidates)
                    {
                        if (data.Where(x => x.Id == el.Id && x.Category == el.Category).FirstOrDefault() != null)
                        {
                            if (el.Likes == null)
                            {
                                el.Likes = new int();
                            }
                            el.Likes++;
                        }
                    }

                    db.Save();
                    String name = (String)Session["UserEmail"];
                    var user = db.context.Users.Where(x => x.Email == name).FirstOrDefault();
                    user.IsVoted = new int();
                    user.IsVoted = 1;
                    Session["IsVoted"] = true;
                    db.Save();

                }
            }
            return "true";
        }
 public ActionResult Index()
 {
     if (Session["isAuth"] != null && (Boolean)Session["isAuth"] == true)
     {
         List<Сandidate> candidates = new List<Сandidate>();
         using (var db = new DbRepository(new dbname123Entities()))
         {
             candidates = db.GetСandidate().ToList();
         }
         return View(candidates);
     }
     else
         return RedirectToAction("Index", "Home");
 }
 public ActionResult CheckPassword(string email, string password)
 {
     var db = new DbRepository(new dbname123Entities());
     var user = db.context.Users.Where(x => x.Email == email && x.Password == password).First();
     if (user != null)
     {
         db.Dispose();
         Session["isAuth"] = true;
         Session["UserEmail"] = user.Email;
         return RedirectToAction("Index", "Poll");
     }
     db.Dispose();
     return RedirectToAction("Index", new { login = "******" });
 }
 //
 // GET: /Home/
 public Object Index()
 {
     try
     {
         using (var db = new DbRepository(new dbname123Entities()))
         {
             var forSpeed = db.context.Users.Select(x => x.Id).First();
         }
         return View();
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
 }
        public String CheckUserSendMessage(User user)
        {
            try
            {
                String response = String.Empty;
                if (user != null)
                {

                    using (var db = new DbRepository(new dbname123Entities()))
                    {
                        var existUser = db.context.Users
                            .Where(x => x.FirstName == user.FirstName && x.SurName == user.SurName
                                && x.Room == user.Room)
                            .FirstOrDefault();
                        if (existUser != null)
                        {
                            if (existUser.IsVoted.HasValue)
                                response = "IsVoted";
                            else
                            {
                                var existEmail = db.context.Users.Where(x => x.Email == user.Email && x.Id!=existUser.Id).FirstOrDefault();
                                if (existEmail != null) response = "ExistEmail";
                                else
                                {
                                    existUser.Email = user.Email;
                                    db.UpdateUser(existUser);
                                    db.Save();
                                    response = user.Email;
                                }
                            }
                        }
                        else
                        {
                            response = "NotExist";
                        }
                    }
                }
                return response;
            }
            catch (Exception)
            {
                return String.Empty;
            }
        }
        public void SendMessage(string email)
        {
            try
            {
                if (email != null)
                {

                    using (var db = new DbRepository(new dbname123Entities()))
                    {
                        var existUser = db.context.Users
                            .Where(x => x.Email == email)
                            .FirstOrDefault();
                        if (existUser != null)
                        {
                            var mail = new EmailMessage();
                            mail.CreateMessage(email);
                            var pass = mail.SendMessage();
                            existUser.Password = pass;
                            db.Save();
                        }
                    }
                }
            }
            catch (Exception)
            {

            }
        }