/// <summary>
 /// Create a new Ban object.
 /// </summary>
 /// <param name="ip">Initial value of the ip property.</param>
 /// <param name="attempt">Initial value of the attempt property.</param>
 public static Ban CreateBan(global::System.String ip, global::System.Int32 attempt)
 {
     Ban ban = new Ban();
     ban.ip = ip;
     ban.attempt = attempt;
     return ban;
 }
 public bool UserValidation(string login, string password)
 {
     bool isUserExists = false;
     string ipAddress = HttpContext.Request.UserHostAddress;
     var ban = _db.Ban.SingleOrDefault(u => u.ip == ipAddress);
     foreach (Users currentUser in _db.Users)
     {
         if (currentUser.Login.Equals(login) &&
             currentUser.Password.Equals(password))
         {
             isUserExists = true;
             if (ban != null) _db.Ban.DeleteObject(ban);
             break;
         }
     }
     if (!isUserExists)
     {
         if (ban == null)
         {
             var b = new Ban {ip = ipAddress, attempt = 1, bantime = null};
             _db.Ban.AddObject(b);
         }
         else // Баним на 10 минут.
         if (ban.attempt == 5)
         {
             ban.bantime = DateTime.Now.AddMinutes(10);
             ViewBag.Error = 3;
         }
         else ban.attempt = ban.attempt + 1;
     }
     _db.SaveChanges();
     return isUserExists;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Ban EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBan(Ban ban)
 {
     base.AddObject("Ban", ban);
 }