コード例 #1
0
        //TODO change to return the userid
        public int Login(string username, string password)
        {
            int    count      = 0;
            string pwdEncrypt = Comon.GetEncryptText(password);
            var    user       = db.Users.Where(p => p.Username == username && p.Password == pwdEncrypt).FirstOrDefault();

            if (user != null)
            {
                Comon.UserId    = user.Id;
                Comon.Authority = user.Authority;
                count           = 1;
            }

            return(count);
        }
コード例 #2
0
        public long AddOrUpdateUser(User user)
        {
            long retour = 0;

            if (user != null)
            {
                User userToCreateOrUpdate = null;

                userToCreateOrUpdate = (user.Id > 0) ? db.Users.Find(user.Id) : db.Users.Create();
                if (db.Users.Where(p => p.Username == user.Username).FirstOrDefault() != null && user.Id == 0)
                {
                    return(0);
                }
                userToCreateOrUpdate.Username  = user.Username;
                userToCreateOrUpdate.Password  = Comon.GetEncryptText(user.Password);
                userToCreateOrUpdate.Authority = user.Authority;

                db.Entry(userToCreateOrUpdate).State = (user.Id > 0) ? EntityState.Modified : EntityState.Added;
                db.SaveChanges();//TODO: async
                retour = userToCreateOrUpdate.Id;
            }

            return(retour);
        }