Beispiel #1
0
        internal bool Update(User data, User before)
        {
            bool result = false;

            try
            {
                bool         valid   = true;
                AasUserCheck checker = new AasUserCheck(param);
                valid = valid && checker.VerifyRequireField(data);
                valid = valid && checker.IsUnLock(before);
                valid = valid && checker.ExistsLoginname(data.Loginname, data.Id);
                if (valid)
                {
                    if (!DAOWorker.AasUserDAO.Update(data))
                    {
                        BugUtil.SetBugCode(param, LibraryBug.Bug.Enum.AasUser_CapNhatThatBai);
                        throw new Exception("Cap nhat thong tin AasUser that bai." + LogUtil.TraceData("data", data));
                    }
                    this.beforeUpdateAasUsers.Add(before);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                LogSystem.Error(ex);
                param.HasException = true;
                result             = false;
            }
            return(result);
        }
Beispiel #2
0
        internal bool Create(User data)
        {
            bool result = false;

            try
            {
                bool            valid           = true;
                PasswordManager passwordManager = new PasswordManager();
                AasUserCheck    checker         = new AasUserCheck(param);
                valid = valid && checker.VerifyRequireField(data);
                valid = valid && checker.ExistsLoginname(data.Loginname, null);
                if (valid)
                {
                    string password = "";
                    if (!String.IsNullOrWhiteSpace(data.Password))
                    {
                        password = data.Password;
                    }
                    else
                    {
                        password = data.Loginname;
                    }
                    data.Salt     = passwordManager.GenerateSalt();
                    data.Password = passwordManager.HashPassword(password, data.Salt, data.Loginname);

                    if (!DAOWorker.AasUserDAO.Create(data))
                    {
                        BugUtil.SetBugCode(param, LibraryBug.Bug.Enum.AasUser_ThemMoiThatBai);
                        throw new Exception("Them moi thong tin AasUser that bai." + LogUtil.TraceData("data", data));
                    }
                    data.Password = "";
                    data.Salt     = "";
                    this.recentAasUsers.Add(data);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                LogSystem.Error(ex);
                param.HasException = true;
                result             = false;
            }
            return(result);
        }
Beispiel #3
0
        internal bool UpdateList(List <User> listData)
        {
            bool result = false;

            try
            {
                bool valid = true;
                valid = IsNotNullOrEmpty(listData);
                AasUserCheck checker = new AasUserCheck(param);
                List <User>  listRaw = new List <User>();
                List <long>  listId  = listData.Select(o => o.Id).ToList();
                valid = valid && checker.VerifyIds(listId, listRaw);
                valid = valid && checker.IsUnLock(listRaw);
                foreach (var data in listData)
                {
                    valid = valid && checker.VerifyRequireField(data);
                    valid = valid && checker.ExistsLoginname(data.Loginname, data.Id);
                }
                if (valid)
                {
                    if (!DAOWorker.AasUserDAO.UpdateList(listData))
                    {
                        BugUtil.SetBugCode(param, LibraryBug.Bug.Enum.AasUser_CapNhatThatBai);
                        throw new Exception("Cap nhat thong tin AasUser that bai." + LogUtil.TraceData("listData", listData));
                    }
                    this.beforeUpdateAasUsers.AddRange(listRaw);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                LogSystem.Error(ex);
                param.HasException = true;
                result             = false;
            }
            return(result);
        }