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 <ServiceStatusListItem <TodoItem> > TodoSearchAsync(FilterItem filter) { ServiceStatusListItem <TodoItem> result = new ServiceStatusListItem <TodoItem>(); try { int startIndex = (filter.Page - 1) * filter.Size; result.Data = new List <TodoItem>(); using (var db = new DBCommand(_connectionString, Queries.Search, true)) { db.AddParameterInt("@startIndex", startIndex); db.AddParameterInt("@pageSize", filter.Size); db.AddParameterStringNull("@text", 100, filter.Text); db.AddParameterInt("@idCategory", filter.IDCategory); db.AddParameterInt("@status", filter.Status); db.AddParameterString("@sort", 100, filter.Sort); result.ReturnValue = await db.ExecuteReaderWhileAsync((dr, rowNumber) => { result.Data.Add(new TodoItem { ID = dr.GetInt("id"), Date = dr.GetDateTime("date"), Title = dr.GetString("title"), IDCategory = dr.GetInt("idCategory"), Category = dr.GetString("category"), Color = dr.GetString("color"), Completed = dr.GetDateTimeNull("completed"), Modified = dr.GetDateTime("modified"), Created = dr.GetDateTime("created"), TotalItems = dr.GetInt("totalItems") }); }); } result.Success = true; } catch (Exception ex) { result.AddError(ex); } return(result); }