Beispiel #1
0
        public IActionResult Delete(string id)
        {
            var model = _roleServices.QueryableToEntity(c => c.RoleId == SqlFunc.ToInt64(id));

            if (model.RoleType == "admin")
            {
                return(BootJsonH((false, PubConst.Role1)));
            }
            var user = _userServices.IsAny(c => c.RoleId == SqlFunc.ToInt64(id));

            if (user)
            {
                return(BootJsonH((false, PubConst.Role3)));
            }
            var flag = _roleServices.Update(new Sys_role {
                RoleId = SqlFunc.ToInt64(id), IsDel = 0, ModifiedBy = UserDtoCache.UserId, ModifiedDate = DateTimeExt.DateTime
            }, c => new { c.IsDel, c.ModifiedBy, c.ModifiedDate });

            if (flag)
            {
                _rolemenuServices.Delete(c => c.RoleId == SqlFunc.ToInt64(id));
                return(BootJsonH((flag, PubConst.Delete1)));
            }
            else
            {
                return(BootJsonH((flag, PubConst.Delete2)));
            }
        }
        public IActionResult AddOrUpdate([FromForm] Sys_user sys_User, [FromForm] string id)
        {
            var validator            = new SysUserFluent();
            ValidationResult results = validator.Validate(sys_User);
            bool             success = results.IsValid;

            if (!success)
            {
                string msg = results.Errors.Aggregate("", (current, item) => (current + item.ErrorMessage + "</br>"));
                return(BootJsonH((PubEnum.Failed.ToInt32(), msg)));
            }
            if (id.IsEmptyZero())
            {
                if (_userServices.IsAny(c => c.UserNickname == sys_User.UserNickname))
                {
                    return(BootJsonH((false, PubConst.User1)));
                }
                sys_User.UserId    = PubId.SnowflakeId;
                sys_User.Pwd       = sys_User.Pwd.ToMd5();
                sys_User.CreateBy  = UserDtoCache.UserId;
                sys_User.LoginTime = 0;
                sys_User.HeadImg   = Path.Combine("upload", "head", "4523c812eb2047c39ad91f8c5de3fb31.jpg");
                bool flag = _userServices.Insert(sys_User);
                return(BootJsonH(flag ? (flag, PubConst.Add1) : (flag, PubConst.Add2)));
            }
            else
            {
                sys_User.UserId       = id.ToInt64();
                sys_User.ModifiedBy   = UserDtoCache.UserId;
                sys_User.ModifiedDate = DateTimeExt.DateTime;
                bool flag = _userServices.Update(sys_User);
                return(BootJsonH(flag ? (flag, PubConst.Update1) : (flag, PubConst.Update2)));
            }
        }