Exemplo n.º 1
0
        public async Task <IList <Widget> > GetAll()     //should probably return the operation result
        {
            var result = await _repository.Get();

            if (result.Success)
            {
                return(result.Result);
            }
            else
            {
                return(new List <Widget>());
            }
        }
Exemplo n.º 2
0
        public async Task <XOFFOperationResult> SeedIfEmpty()
        {
            try
            {
                var getWidgetsResult = await _repository.Get();

                if (!getWidgetsResult.Success || !getWidgetsResult.Result.Any())
                {
                    var widgets = new List <Widget>();
                    for (int i = 0; i < 15; i++)
                    {
                        var guid = Guid.NewGuid();
                        widgets.Add(new Widget()
                        {
                            LocalId = guid,
                            Name    = guid.ToString()
                        });
                    }
                    _repository.Insert(widgets);
                }
                return(XOFFOperationResult.CreateSuccessResult("There are widgets saved"));
            }
            catch (Exception e)
            {
                return(XOFFOperationResult.CreateFailure(e.Message));
            }
        }