public IActionResult AddOrUpdate([FromForm] Wms_Customer model, [FromForm] string id) { var validator = new CustomerFluent(); 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 (_customerServices.IsAny(c => c.CustomerNo == model.CustomerNo || c.CustomerName == model.CustomerName)) { return(BootJsonH((false, PubConst.Customer1))); } model.CustomerId = PubId.SnowflakeId; model.CreateBy = UserDtoCache.UserId; bool flag = _customerServices.Insert(model); return(BootJsonH(flag ? (flag, PubConst.Add1) : (flag, PubConst.Add2))); } else { model.CustomerId = id.ToInt64(); model.ModifiedBy = UserDtoCache.UserId; model.ModifiedDate = DateTimeExt.DateTime; var flag = _customerServices.Update(model); return(BootJsonH(flag ? (flag, PubConst.Update1) : (flag, PubConst.Update2))); } }
public (bool, string) Import(System.Data.DataTable dt, long userId) { if (dt.IsNullDt()) { return(false, PubConst.Import1); } var validator = new CustomerFluent(); var list = new List <Wms_Customer>(); string[] header = { "客户编号", "客户名称", "电话", "邮箱", "联系人", "地址" }; foreach (var item in header) { if (!dt.Columns.Contains(item)) { return(false, "不包含Excel表头:" + string.Join(",", header)); } } int dtCount = dt.Rows.Count; for (int i = 0; i < dtCount; i++) { var model = new Wms_Customer { CustomerNo = dt.Rows[i]["客户编号"].ToString(), CustomerName = dt.Rows[i]["客户名称"].ToString(), Address = dt.Rows[i]["地址"].ToString(), Tel = dt.Rows[i]["电话"].ToString(), Email = dt.Rows[i]["邮箱"].ToString(), CustomerPerson = dt.Rows[i]["联系人"].ToString(), }; var results = validator.Validate(model); var success = results.IsValid; if (!success) { string msg = results.Errors.Aggregate("", (current, item) => (item.ErrorMessage + "</br>")); return(false, msg); } if (_repository.IsAny(c => c.CustomerNo == model.CustomerNo)) { return(false, PubConst.Customer1); } model.CustomerId = PubId.SnowflakeId; model.CreateBy = userId; list.Add(model); } var flag = _repository.InsertTran(list); if (flag.IsSuccess) { return(true, PubConst.Import2); } else { var _nlog = ServiceResolve.Resolve <ILogUtil>(); _nlog.Debug(flag.ErrorMessage); return(false, PubConst.Import3); } }