Beispiel #1
0
        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);
        }