public void AddActivity(string summary, string content, string host, bool isLocal, DateTime? startTime, DateTime? endTime) { try { Activity model = new Activity() { Id = Guid.NewGuid(), Summary = StringHelper.LimitLength(summary, 500), Content = content, CreateTime = DateTime.Now, Host = StringHelper.LimitLength(host, 100), IsLocal = isLocal, IsSeen = true, StartTime = startTime ?? DateTime.Now, EndTime = startTime ?? DateTime.Now }; db.AddToActivities(model); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
/// <summary> /// 创建新的 Activity 对象。 /// </summary> /// <param name="id">Id 属性的初始值。</param> /// <param name="content">Content 属性的初始值。</param> /// <param name="summary">Summary 属性的初始值。</param> /// <param name="createTime">CreateTime 属性的初始值。</param> /// <param name="startTime">StartTime 属性的初始值。</param> /// <param name="endTime">EndTime 属性的初始值。</param> /// <param name="host">Host 属性的初始值。</param> /// <param name="isSeen">IsSeen 属性的初始值。</param> /// <param name="isLocal">IsLocal 属性的初始值。</param> public static Activity CreateActivity(global::System.Guid id, global::System.String content, global::System.String summary, global::System.DateTime createTime, global::System.DateTime startTime, global::System.DateTime endTime, global::System.String host, global::System.Boolean isSeen, global::System.Boolean isLocal) { Activity activity = new Activity(); activity.Id = id; activity.Content = content; activity.Summary = summary; activity.CreateTime = createTime; activity.StartTime = startTime; activity.EndTime = endTime; activity.Host = host; activity.IsSeen = isSeen; activity.IsLocal = isLocal; return activity; }
/// <summary> /// 用于向 Activities EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToActivities(Activity activity) { base.AddObject("Activities", activity); }