Esempio n. 1
0
        public BaseState AddAdmin(Admin collection)
        {
            if (this.ExistUserid(collection.Userid))
            {

                return new BaseState
                           {
                               ErrorCode = -1,
                               ErrorMessage = "已经存在此用户名"
                           };

            }

            if (this.ExistUName(collection.Uname))
            {

                return new BaseState
                {
                    ErrorCode = -1,
                    ErrorMessage = "已经存在此笔名"
                };
            }

            var password = Dev.Comm.Security.GetMD5(collection.Pwd);
            collection.Pwd = password;

            this._adminRepository.Add(collection);

            this._adminRepository.UnitOfWork.SaveChanges();


            if (collection.AdminId > 0)
            {
                return new BaseState();
            }

            return new BaseState(-1, "未知错误");
        }
Esempio n. 2
0
        public BaseState EditAdmin(Admin collection)
        {
            var model = this._adminRepository.GetByKey(collection.AdminId);


            if (model.Uname != collection.Uname && this.ExistUName(collection.Uname))
            {

                return new BaseState
                {
                    ErrorCode = -1,
                    ErrorMessage = "已经存在此笔名"
                };
            }

            model.Uname = collection.Uname;

            if (!string.IsNullOrWhiteSpace(collection.Pwd))
            {
                var password = Dev.Comm.Security.GetMD5(collection.Pwd);
                model.Pwd = password;
            }

            model.Tname = collection.Tname;
            model.Email = collection.Email;
            model.Typeid = collection.Typeid;

            this._adminRepository.Update(model);

            this._adminRepository.UnitOfWork.SaveChanges();

            if (model.AdminId > 0)
            {
                return new BaseState();
            }

            return new BaseState(-1, "未知错误");
        }