/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <Spl_WareCategoryModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { Spl_WareCategory entity = new Spl_WareCategory(); entity.Id = ResultHelper.NewId; entity.Name = model.Name; entity.Code = model.Code; entity.ParentId = model.ParentId; entity.Remark = model.Remark; entity.CreateTime = ResultHelper.NowTime; entity.Enable = model.Enable; db.Spl_WareCategory.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
public virtual Spl_WareCategoryModel GetById(object id) { if (IsExists(id)) { Spl_WareCategory entity = m_Rep.GetById(id); Spl_WareCategoryModel model = new Spl_WareCategoryModel(); model.Id = entity.Id; model.Name = entity.Name; model.Code = entity.Code; model.ParentId = entity.ParentId; model.Remark = entity.Remark; model.CreateTime = entity.CreateTime; model.Enable = entity.Enable; return(model); } else { return(null); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_WareCategoryModel model) { ValidationErrors errors = new ValidationErrors(); try { Spl_WareCategory entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new Spl_WareCategory(); entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.ParentId = model.ParentId; entity.Remark = model.Remark; entity.CreateTime = model.CreateTime; entity.Enable = model.Enable; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public virtual bool Edit(ref ValidationErrors errors, Spl_WareCategoryModel model) { try { Spl_WareCategory entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.ParentId = model.ParentId; entity.Remark = model.Remark; entity.CreateTime = model.CreateTime; entity.Enable = model.Enable; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual bool Create(ref ValidationErrors errors, Spl_WareCategoryModel model) { try { Spl_WareCategory entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new Spl_WareCategory(); entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.ParentId = model.ParentId; entity.Remark = model.Remark; entity.CreateTime = model.CreateTime; entity.Enable = model.Enable; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }