Ejemplo n.º 1
0
        private static int GetId()
        {
            bool IsIdExists(int id)
            {
                using (var db = new PutBoxSqlModel())
                {
                    return(db.FileDatas.Any(x => x.id == id) ||
                           db.FolderDatas.Any(x => x.id == id) ||
                           db.UserDatas.Any(x => x.id == id));
                }
            }

            using (var db = new PutBoxSqlModel())
            {
                var size = db.UserDatas.Count() + db.FileDatas.Count() + db.FolderDatas.Count();
                while (true)
                {
                    var tmpId = new Random().Next(0, size + 1);
                    if (!IsIdExists(tmpId))
                    {
                        return(tmpId);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public string GetPath(UserInfo user)
 {
     using (var db = new PutBoxSqlModel())
     {
         var tmpPassword = user.Password.GetHashCode().ToString();
         return(db.UserDatas.First(x => x.email == user.Email &&
                                   x.password == tmpPassword).path);
     }
 }
Ejemplo n.º 3
0
 public bool Login(UserInfo user)
 {
     using (var db = new PutBoxSqlModel())
     {
         var tmpPassword = user.Password.GetHashCode().ToString();
         return(db.UserDatas.Any(x => x.email == user.Email &&
                                 x.password == tmpPassword));
     }
 }
Ejemplo n.º 4
0
 public bool Register(string email, string password)
 {
     using (var db = new PutBoxSqlModel())
     {
         if (db.UserDatas.Any(x => x.email == email))
         {
             return(false);
         }
         var tmpId = GetId();
         db.UserDatas.Add(new UserData()
         {
             email    = email,
             password = password.GetHashCode().ToString(),
             id       = tmpId,
             path     = $@"/{tmpId}"
         });
         db.SaveChanges();
     }
     return(true);
 }