public IActionResult AddOrUpdateD([FromForm] List <Wms_invmovedetail> list, [FromForm] string id) { var validator = new InvmovedetailFluent(); foreach (var c in list) { var results = validator.Validate(c); var success = results.IsValid; if (!success) { string msg = results.Errors.Aggregate("", (current, item) => (current + item.ErrorMessage + "</br>")); return(BootJsonH((PubEnum.Failed.ToInt32(), msg))); } } var exist = _invmovedetailServices.QueryableToList(c => c.InventorymoveId == SqlFunc.ToInt64(id)); var modelList = new List <Wms_invmovedetail>(); if (exist.IsNullT()) { list.ForEach((c) => { c.Remark = _xss.Filter(c.Remark); c.MoveDetailId = PubId.SnowflakeId; c.Status = StockInStatus.initial.ToByte(); c.IsDel = 1; c.CreateBy = UserDtoCache.UserId; c.CreateDate = DateTimeExt.DateTime; modelList.Add(c); }); bool flag = _invmovedetailServices.Insert(modelList); return(BootJsonH(flag ? (flag, PubConst.Add1) : (flag, PubConst.Add2))); } else { _invmovedetailServices.Update(new Wms_invmovedetail { IsDel = 0, ModifiedBy = UserDtoCache.UserId, ModifiedDate = DateTimeExt.DateTime }, c => new { c.IsDel, c.ModifiedBy, c.ModifiedDate }, c => c.InventorymoveId == SqlFunc.ToInt64(id) && c.IsDel == 1); list.ForEach((c) => { c.Remark = _xss.Filter(c.Remark); c.Status = StockInStatus.initial.ToByte(); c.MoveDetailId = PubId.SnowflakeId; c.IsDel = 1; c.CreateBy = UserDtoCache.UserId; c.CreateDate = DateTimeExt.DateTime; modelList.Add(c); }); var flag = _invmovedetailServices.Insert(modelList); return(BootJsonH(flag ? (flag, PubConst.Update1) : (flag, PubConst.Update2))); } }
private object ModelFieldFilter(string key, Type t, object obj) { //获取类的属性集合 //var ats = t.GetCustomAttributes(typeof(FieldFilterAttribute), false); if (obj != null) { //Type type = obj.GetType().GetGenericArguments()[0]; //获取类的属性集合 var pps = t.GetProperties(); foreach (var pp in pps) { if (!pp.CanWrite) { continue; } if (pp.GetValue(obj) != null) { //当属性等于字符串 if (pp.PropertyType == typeof(string)) { string value = pp.GetValue(obj).ToString(); pp.SetValue(obj, _xss.Filter(value)); } else if (pp.PropertyType.IsClass)//当属性等于类进行递归 { pp.SetValue(obj, ModelFieldFilter(pp.Name, pp.PropertyType, pp.GetValue(obj))); } } } } return(obj); }
public async Task <IActionResult> CheckLoginAsync([FromBody] SysUserDto sys) { ClearCache("user"); ClearCache("menu"); var item = _userServices.CheckLogin(sys); if (item.Item1) { await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); var claims = new List <Claim> { new Claim(ClaimTypes.Name, item.Item3.UserName), new Claim(ClaimTypes.Sid, item.Item3.UserId.ToString()), new Claim(ClaimTypes.Surname, item.Item3.UserNickname), new Claim(ClaimTypes.Role, item.Item3.RoleId?.ToString()), new Claim(ClaimTypes.Uri, string.IsNullOrWhiteSpace(item.Item3.HeadImg)?Path.Combine("upload", "head", "4523c812eb2047c39ad91f8c5de3fb31.jpg"):item.Item3.HeadImg) }; var claimsIdentitys = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var claimsPrincipal = new ClaimsPrincipal(claimsIdentitys); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties { IssuedUtc = DateTime.Now, IsPersistent = true, ExpiresUtc = DateTime.Now.AddDays(1), }); } else { await _mediator.Publish(new Sys_log { LogId = PubId.SnowflakeId, Browser = GetBrowser(), Description = $"{_xss.Filter(sys.UserNickname)}登录失败", LogIp = GetIp(), Url = GetUrl(), LogType = LogType.login.EnumToString() }); //_logServices.Insert(new Sys_log //{ // LogId = PubId.SnowflakeId, // Browser = GetBrowser(), // Description = $"{_xss.Filter(sys.UserNickname)}登录失败", // LogIp = GetIp(), // Url = GetUrl(), // LogType = LogType.login.EnumToString() //}); } item.Item3 = null; return(Json(item)); }
public override void OnActionExecuting(ActionExecutingContext context) { var req = context.HttpContext.Request; var ps = context.ActionDescriptor.Parameters; _xss = context.HttpContext.RequestServices.GetService(typeof(Xss)) as Xss; foreach (var p in ps) { if (context.ActionArguments[p.Name] != null) { //当参数等于字符串 if (p.ParameterType == typeof(string)) { context.ActionArguments[p.Name] = _xss.Filter(context.ActionArguments[p.Name].ToString()); } else if (p.ParameterType.IsClass)//当参数等于类 { ModelFieldFilter(p.Name, p.ParameterType, context.ActionArguments[p.Name]); } } } //var qs = QueryHelpers.ParseQuery(req.QueryString.ToUriComponent()); //var ret = new QueryString(); //foreach (var k in qs.Keys) //{ // for (var i = 0; i < qs[k].Count(); i++) // { // try // { // ret.Add(k, _xss.Filter(qs[k][i])); // } // catch // { // ret.Add(k, qs[k][i]); // } // } //} //req.QueryString = ret; base.OnActionExecuting(context); }