public void UpdateTaskTest() { CreateTaskTest(); wait.Reset(); var app = Taskboard.Apps.TaskboardApp.Applcation; var entity = new TaskEntity(); entity.Copy(app.Tasks[0]); entity.Categoly = "InProgress"; entity.Title = "TestTitle"; entity.Contents = "TestContents"; Assert.AreEqual(1, app.Tasks.Count); Assert.AreEqual(1, app.Tasks[0].Id); Assert.AreEqual("ToDo", app.Tasks[0].Categoly); Assert.AreEqual("新しいタスク", app.Tasks[0].Title); Assert.IsNull(app.Tasks[0].Contents); app.UpdateTask(entity); wait.WaitOne(); Assert.AreEqual(1, app.Tasks.Count); Assert.AreEqual(1, app.Tasks[0].Id); Assert.AreEqual("InProgress", app.Tasks[0].Categoly); Assert.AreEqual("TestTitle", app.Tasks[0].Title); Assert.AreEqual("TestContents", app.Tasks[0].Contents); }
public TaskEntity UpdateTask(TaskEntity entity) { using (var tran = connection.BeginTransaction()) { try { connection.Execute(String.Format("UPDATE {0} SET categoly=@Categoly,title=@Title,contents=@Contents WHERE id=@Id", Resource.TableName), entity, tran); tran.Commit(); // TODO:Commit後にコレは… var sql = String.Format("SELECT id, categoly, title, contents FROM {0} WHERE id='{1}' LIMIT 1", Resource.TableName, entity.Id); return connection.Query<TaskEntity>(sql).FirstOrDefault(); } catch { tran.Rollback(); throw; } } }
/// <summary> /// Entityの内容をコピーします /// </summary> /// <param name="source"></param> public void Copy(TaskEntity source) { foreach (var property in this.GetType().GetProperties()) { property.SetValue(this, property.GetValue(source)); } }
public TaskEntity CreateCopy() { var entity = new TaskEntity(); entity.Copy(this); return entity; }
/// <summary> /// Taskを更新します /// </summary> /// <param name="requestId"></param> public void UpdateTask(TaskEntity entity, string requestId = null) { Task.Factory.StartNew(() => { TaskEntity result = null; using (var client = new SQLiteRepositoryClient()) { result = client.UpdateTask(entity); } var localEntity = Tasks.Single(s => s.Id == result.Id); localEntity.Copy(result); // 変更を通知 if (EntityChanged != null) EntityChanged(this, new EntityChangedEventArgs(NotifyEntityChangedAction.Update, localEntity)); // 成功を通知 if (Responded != null) Responded(this, new UpdateOperationEventArgs(true, requestId)); }). ContinueWith(result => { // 失敗を通知 if (Responded != null) Responded(this, new UpdateOperationEventArgs(false, requestId)); }, TaskContinuationOptions.OnlyOnFaulted); }
/// <summary> /// 参照を共有しない同一内容の新しいインスタンスを生成します /// </summary> /// <returns></returns> public ViewModel Clone() { var newEntity = new TaskEntity(); newEntity.Copy(this.Entity); return new TaskViewModel(newEntity); }
public TaskViewModel(TaskEntity entity) : this() { this.Entity = entity; }