public IActionResult AddOrUpdate([FromForm] Wms_material model, [FromForm] string id) { var validator = new MaterialFluent(); var results = validator.Validate(model); var 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 (_materialServices.IsAny(c => c.MaterialNo == model.MaterialNo || c.MaterialName == model.MaterialName)) { return(BootJsonH((false, PubConst.Material1))); } model.MaterialId = PubId.SnowflakeId; model.CreateBy = UserDtoCache.UserId; bool flag = _materialServices.Insert(model); return(BootJsonH(flag ? (flag, PubConst.Add1) : (flag, PubConst.Add2))); } else { model.MaterialId = id.ToInt64(); model.ModifiedBy = UserDtoCache.UserId; model.ModifiedDate = DateTimeExt.DateTime; var flag = _materialServices.Update(model); return(BootJsonH(flag ? (flag, PubConst.Update1) : (flag, PubConst.Update2))); } }
public IActionResult AddOrUpdate([FromForm] Wms_material model, [FromForm] string id) { var validator = new MaterialFluent(); var results = validator.Validate(model); var success = results.IsValid; if (!success) { string msg = results.Errors.Aggregate("", (current, item) => (current + item.ErrorMessage + "</br>")); return(BootJsonH((PubEnum.Failed.ToInt32(), msg))); } Sys_dict unitDict = _client.Queryable <Sys_dict>().First(x => x.DictId == model.Unit && x.DictType == PubDictType.unit.ToInt32().ToString()); if (unitDict == null) { return(BootJsonH((false, PubConst.UnitNotFound))); } Sys_dict typeDict = _client.Queryable <Sys_dict>().First(x => x.DictId == model.MaterialType && x.DictType == PubDictType.material.ToInt32().ToString()); if (typeDict == null) { return(BootJsonH((false, PubConst.MaterialTypeNotFound))); } if (id.IsEmptyZero()) { if (_materialServices.IsAny(c => c.MaterialNo == model.MaterialNo || c.MaterialName == model.MaterialName)) { return(BootJsonH((false, PubConst.Material1))); } model.MaterialId = PubId.SnowflakeId; model.UnitName = unitDict.DictName; model.MaterialTypeName = typeDict.DictName; model.CreateBy = UserDtoCache.UserId; model.CreateDate = DateTime.Now; model.CreateUser = UserDtoCache.UserName; model.ModifiedBy = UserDtoCache.UserId; model.ModifiedDate = DateTime.Now; model.ModifiedUser = UserDtoCache.UserName; bool flag = _materialServices.Insert(model); return(BootJsonH(flag ? (flag, PubConst.Add1) : (flag, PubConst.Add2))); } else { model.MaterialId = id.ToInt64(); model.UnitName = unitDict.DictName; model.MaterialTypeName = typeDict.DictName; model.ModifiedBy = UserDtoCache.UserId; model.ModifiedDate = DateTimeExt.DateTime; var flag = _materialServices.Update(model); return(BootJsonH(flag ? (flag, PubConst.Update1) : (flag, PubConst.Update2))); } }