public virtual SysCalendarPlanModel GetById(object id) { if (IsExists(id)) { SysCalendarPlan entity = m_Rep.GetById(id); SysCalendarPlanModel model = new SysCalendarPlanModel(); model.Id = entity.Id; model.Title = entity.Title; model.PlanContent = entity.PlanContent; model.BeginDate = entity.BeginDate; model.EndDate = entity.EndDate; model.CreateTime = entity.CreateTime; model.Url = entity.Url; model.Color = entity.Color; model.TextColor = entity.TextColor; model.SysUserId = entity.SysUserId; model.Editable = entity.Editable; return(model); } else { return(null); } }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <SysCalendarPlanModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { SysCalendarPlan entity = new SysCalendarPlan(); entity.Id = ResultHelper.NewId; entity.Title = model.Title; entity.PlanContent = model.PlanContent; entity.BeginDate = model.BeginDate; entity.EndDate = model.EndDate; entity.CreateTime = ResultHelper.NowTime; entity.Url = model.Url; entity.Color = model.Color; entity.TextColor = model.TextColor; entity.SysUserId = model.SysUserId; entity.Editable = model.Editable; db.SysCalendarPlan.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(SysCalendarPlanModel model) { ValidationErrors errors = new ValidationErrors(); try { SysCalendarPlan entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new SysCalendarPlan(); entity.Id = model.Id; entity.Title = model.Title; entity.PlanContent = model.PlanContent; entity.BeginDate = model.BeginDate; entity.EndDate = model.EndDate; entity.CreateTime = model.CreateTime; entity.Url = model.Url; entity.Color = model.Color; entity.TextColor = model.TextColor; entity.SysUserId = model.SysUserId; entity.Editable = model.Editable; 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 Create(ref ValidationErrors errors, SysCalendarPlanModel model) { try { SysCalendarPlan entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new SysCalendarPlan(); entity.Id = model.Id; entity.Title = model.Title; entity.PlanContent = model.PlanContent; entity.BeginDate = model.BeginDate; entity.EndDate = model.EndDate; entity.CreateTime = model.CreateTime; entity.Url = model.Url; entity.Color = model.Color; entity.TextColor = model.TextColor; entity.SysUserId = model.SysUserId; entity.Editable = model.Editable; 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); } }