예제 #1
0
        public IActionResult AddOrUpdate([FromForm] Sys_role role, [FromForm] string id, [FromForm] string[] menuIds)
        {
            //int[] menuIds = Array.ConvertAll(menuId, new Converter<string, int>(c => c.ToInt32()));
            //Array.Sort(menuIds);
            //var arrs = (from d in menuId orderby d.ToInt32() ascending select d.ToInt32()).ToArray();
            //var arrs2 = (from d in arrs select d).ToArray();

            var validator            = new SysRoleFluent();
            ValidationResult results = validator.Validate(role);
            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 (_roleServices.IsAny(c => c.RoleName == role.RoleName))
                {
                    return(BootJsonH((false, PubConst.Role2)));
                }
                var flag = _roleServices.Insert(role, UserDtoCache.UserId, menuIds);
                return(BootJsonH(flag.IsSuccess ? (flag.IsSuccess, PubConst.Add1) : (flag.IsSuccess, PubConst.Add2)));
            }
            else
            {
                //admin
                //var model = _roleServices.QueryableToEntity(c => c.RoleId == SqlFunc.ToInt64(id));
                //if (model.RoleType == "admin")
                //{
                //    return BootJsonH((false, PubConst.Role1));
                //}
                role.RoleId = id.ToInt64();
                var flag = _roleServices.Update(role, UserDtoCache.UserId, menuIds);
                return(BootJsonH(flag.IsSuccess ? (flag.IsSuccess, PubConst.Update1) : (flag.IsSuccess, PubConst.Update2)));
            }
        }