示例#1
0
        public UResult CheckUser(string login, string password)
        {
            using (var db = new FilmFinderDb())
            {
                GetHeshMd5 getHesh   = new GetHeshMd5();
                User       checkUser = new User();
                try
                {
                    checkUser = db.Users.First(i => i.Name == login);
                }
                catch (Exception e)
                {
                    db.Dispose();
                    return(UResult.UserFailed);
                }

                if (checkUser == null)
                {
                    return(UResult.UserFailed);
                }
                else
                {
                    if (checkUser.Password == getHesh.GetHesh(password))
                    {
                        SetCurrentUser(checkUser);
                        return(UResult.Access);
                    }
                    else
                    {
                        return(UResult.PasswordFailed);
                    }
                }
            }
        }
        public int AddNewUserOnDB(RegistrateCurrentUser registrate)
        {
            using (var db = new FilmFinderDb())
            {
                if (db.Users.Any(i => i.Name == registrate.Login))
                {
                    return((int)UResult.UserFailed);
                }
                bool tmpGender = true;
                switch (registrate.Gender)
                {
                case 0:
                    tmpGender = false;
                    break;

                case 1:
                    tmpGender = true;
                    break;
                }
                GetHeshMd5 getHesh = new GetHeshMd5();

                db.Users.Add(new User()
                {
                    DateBirthday = registrate.DateBirthday, Name = registrate.Login, Password = getHesh.GetHesh(registrate.Password), Gender = tmpGender, UserImage = File.ReadAllBytes("./usericon.png")
                });
                db.SaveChanges();
            }
            return((int)UResult.Access);
        }