public virtual bool Create(ref ValidationErrors errors, WMS_HeaderModel model) { try { WMS_Header entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new WMS_Header(); entity.Id = model.Id; entity.Code = model.Code; entity.Name = model.Name; 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); } }
public virtual bool Edit(ref ValidationErrors errors, WMS_HeaderModel model) { try { WMS_Header entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Code = model.Code; entity.Name = model.Name; 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 WMS_HeaderModel GetById(object id) { if (IsExists(id)) { WMS_Header entity = m_Rep.GetById(id); WMS_HeaderModel model = new WMS_HeaderModel(); model.Id = entity.Id; model.Code = entity.Code; model.Name = entity.Name; return(model); } else { return(null); } }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <WMS_HeaderModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { WMS_Header entity = new WMS_Header(); entity.Id = 0; entity.Code = model.Code; entity.Name = model.Name; db.WMS_Header.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }