示例#1
0
        public static Account Login(string userName, string password)
        {
            string hashedPassword = Sha256Helper.GetHashSha256(password);

            Account acc = AuthenticateDAL.Login(userName, hashedPassword);

            if (acc != null)
            {
                AccountDAL.AddToLoginLog(acc);
            }

            return(acc);
        }
示例#2
0
        internal static Account SaveAccount(Account acc)
        {
            using (CoreModel coreDAL = new CoreModel())
            {
                if (acc.ID > 0)
                {
                    Account account = coreDAL.Account.Include("Club").Include("AccountAccess").Include("Account_Information")
                                      .Where(a => a.ID == acc.ID).FirstOrDefault();
                    account.AccountAccess.ToList().ForEach(a => a.Accessright.Accessright_Right.ToList());
                    if (account != null)
                    {
                        account.FirstName = acc.FirstName;
                        account.LastName  = acc.LastName;
                        account.UserName  = acc.UserName;
                        account.Image     = acc.Image;
                        account.Gender    = acc.Gender;

                        account.Account_Information.ToList().ForEach(a => coreDAL.Entry(a).State = System.Data.Entity.EntityState.Deleted);
                        acc.Account_Information.ToList().ForEach(a => account.Account_Information.Add(a));

                        account.AccountAccess.ToList().ForEach(a => coreDAL.Entry(a).State = System.Data.Entity.EntityState.Deleted);
                        acc.AccountAccess.ToList().ForEach(a => account.AccountAccess.Add(a));

                        if (!string.IsNullOrEmpty(acc.Password))
                        {
                            account.Password = Sha256Helper.GetHashSha256(acc.Password);
                        }
                        coreDAL.SaveChanges();

                        return(account);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    acc.Password = Sha256Helper.GetHashSha256(acc.Password);
                    coreDAL.Account.Add(acc);
                    coreDAL.SaveChanges();
                    return(acc);
                }
            }
        }