public async Task <ServiceStatusItem <MyTask> > TodoToggle(MyTaskInput inputData) { ServiceStatusItem <MyTask> result = new ServiceStatusItem <MyTask>(); try { if (inputData.ID.HasValue == false || inputData.ID == 0) { result.AddError("`id` required"); } if (result.Messages.Count > 0) { return(result); } result.Data = _manager.TaskToggle(inputData.ID.Value); if (result.Data != null) { result.AddSuccess("Updated"); } else { result.AddWarning("No change"); } result.Success = true; } catch (Exception ex) { result.AddError(ex); } return(result); }
public async Task <ServiceStatusItem> TodoDeleteAsync(int id) { ServiceStatusItem result = new ServiceStatusItem(); try { if (id == 0) { result.AddError("Ivalid `id`"); } if (result.Messages.Count > 0) { return(result); } using (var db = new DBCommand(_connectionString, Queries.Remove)) { db.AddParameterInt("@id", id); await db.ExecuteNonQueryAsync(); result.AddSuccess($"Deleted id: {id}"); result.Success = true; } } catch (Exception ex) { result.AddError(ex); } return(result); }
public async Task <ServiceStatusItem> TodoUpdateAsync(TodoItem item) { ServiceStatusItem result = new ServiceStatusItem(); try { if (item.ID == 0) { result.AddError("Ivalid `id`"); } if (item.Date.HasValue == false || item.Date.Value < new DateTime(1970, 1, 1)) { result.AddError("`date` required"); } if (string.IsNullOrWhiteSpace(item.Title)) { result.AddError("`title` required"); } if (item.IDCategory < 0) { result.AddError("`idCategory` required"); } if (result.Messages.Count > 0) { return(result); } using (var db = new DBCommand(_connectionString, Queries.Update)) { db.AddParameterInt("@id", item.ID); db.AddParameterDateTime("@date", item.Date); db.AddParameterString("@title", 100, item.Title); db.AddParameterNote("@note", item.Note); db.AddParameterInt("@idCategory", item.IDCategory); db.AddParameterDateTime("@completed", item.Completed); await db.ExecuteNonQueryAsync(); result.AddSuccess($"Updated id: {item.ID}"); result.Success = true; } } catch (Exception ex) { result.AddError(ex); } return(result); }
public async Task <ServiceStatusItem <TodoItem> > TodoCategoryAsync(int id, int idCategory) { ServiceStatusItem <TodoItem> result = new ServiceStatusItem <TodoItem>(); try { using (var db = new DBCommand(_connectionString, Queries.UpdateCategory)) { db.AddParameterInt("@id", id); db.AddParameterInt("@idCategory", idCategory); result.ReturnValue = await db.ExecuteReaderWhileAsync((dr, rowNumber) => { result.Data = new TodoItem { ID = dr.GetInt("id"), IDCategory = dr.GetInt("idCategory") }; }); result.Success = true; } } catch (Exception ex) { result.AddError(ex); } return(result); }
public async Task <ServiceStatusItem <TodoItem> > TodoToggleAsync(int id) { ServiceStatusItem <TodoItem> result = new ServiceStatusItem <TodoItem>(); try { //result.Data = new TodoItem(); using (var db = new DBCommand(_connectionString, Queries.Toggle + Queries.Read)) { db.AddParameterInt("@id", id); result.ReturnValue = await db.ExecuteReaderWhileAsync((dr, rowNumber) => { result.Data = new TodoItem { ID = dr.GetInt("id"), Date = dr.GetDateTime("date").Date, Title = dr.GetString("title"), IDCategory = dr.GetInt("idCategory"), Category = dr.GetString("category"), Completed = dr.GetDateTimeNull("completed"), Modified = dr.GetDateTime("modified"), Created = dr.GetDateTime("created") }; }); result.Success = true; } } catch (Exception ex) { result.AddError(ex); } return(result); }
public async Task <ServiceStatusItem <MyTask> > MyTaskReadAsync(int id) { ServiceStatusItem <MyTask> result = new ServiceStatusItem <MyTask>(); try { result.Data = _manager.TaskGet(id); if (result.Data != null) { result.AddSuccess($"Readed 1"); } else { result.AddSuccess("no data"); } result.Success = true; } catch (Exception ex) { result.AddError(ex); } return(result); }