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