public virtual bool Edit(ref ValidationErrors errors, Spl_ContactCompanyCategoryModel model) { try { Spl_ContactCompanyCategory entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Name = model.Name; entity.CreateTime = model.CreateTime; entity.Category = model.Category; 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_ContactCompanyCategoryModel model) { try { Spl_ContactCompanyCategory entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new Spl_ContactCompanyCategory(); entity.Id = model.Id; entity.Name = model.Name; entity.CreateTime = model.CreateTime; entity.Category = model.Category; 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 Spl_ContactCompanyCategoryModel GetById(object id) { if (IsExists(id)) { Spl_ContactCompanyCategory entity = m_Rep.GetById(id); Spl_ContactCompanyCategoryModel model = new Spl_ContactCompanyCategoryModel(); model.Id = entity.Id; model.Name = entity.Name; model.CreateTime = entity.CreateTime; model.Category = entity.Category; return(model); } else { return(null); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_ContactCompanyCategoryModel model) { ValidationErrors errors = new ValidationErrors(); try { Spl_ContactCompanyCategory entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new Spl_ContactCompanyCategory(); entity.Id = model.Id; entity.Name = model.Name; entity.CreateTime = model.CreateTime; entity.Category = model.Category; 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)); } }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <Spl_ContactCompanyCategoryModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { Spl_ContactCompanyCategory entity = new Spl_ContactCompanyCategory(); entity.Id = ResultHelper.NewId; entity.Name = model.Name; entity.CreateTime = ResultHelper.NowTime; entity.Category = model.Category; db.Spl_ContactCompanyCategory.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }