Esempio n. 1
0
 public ApiController(
     ToDoItemsContext context,
     IConfiguration configuration,
     DbContextOptions<ToDoItemsContext> options)
 {
     _context = context;
     _configuration = configuration;
     _options = options;
 }
Esempio n. 2
0
        public async Task<string> GetAllAsync()
        {
            await using (ToDoItemsContext context = new ToDoItemsContext(_options, _configuration))
            {
                await context.Database.EnsureCreatedAsync();
                List<ToDoItem> getOpenItems = await context.ToDoItems
                    .Where(w => !w.Completed)
                    .ToListAsync();

                return DefaultSerializer(getOpenItems) ?? NoContentResult;
            }
        }
Esempio n. 3
0
        public async Task<string> PostSeedAsync()
        {
            List<ToDoItem> sampleToDoList = new List<ToDoItem>
            {
                new ToDoItem
                {
                    Id = Guid.NewGuid(),
                    Name = "Virtual Golfing with Remote Team",
                    Description =
                        "Engage the remote team in a virtual golfing tournament at the local multi-player arena.",
                    Completed = false,
                },
                new ToDoItem
                {
                    Id = Guid.NewGuid(),
                    Name = "Book International Flight to Sea-Tac",
                    Description = "Departure from Toronto (CYYZ) to destination Seattle (KSEA) sometime next month.",
                    Completed = false,
                },
                new ToDoItem
                {
                    Id = Guid.NewGuid(),
                    Name = "Tour Seattle Space Needle",
                    Description =
                        "The Seattle Space Needle is a landmark observation tower and a must visit location for any tourist.",
                    Completed = false,
                },
            };

            try
            {
                foreach (ToDoItem item in sampleToDoList)
                {
                    await using (ToDoItemsContext context = new ToDoItemsContext(_options, _configuration))
                    {
                        await context.ToDoItems.AddAsync(item);
                        await context.SaveChangesAsync();
                    }
                }

                return $"Iterated {nameof(ToDoItem)} in list {nameof(sampleToDoList)} for {nameof(EntityEntry)} type.";
            }
            catch (CosmosException ce)
            {
                Console.WriteLine(ce);
            }

            return null;
        }
Esempio n. 4
0
        public async Task<string> PostAsync([FromBody] ToDoItem toDoItem)
        {
            try
            {
                if (toDoItem == null)
                {
                    return Error();
                }

                await using (ToDoItemsContext context = new ToDoItemsContext(_options, _configuration))
                {
                    await context.ToDoItems.AddAsync(toDoItem);
                    await context.SaveChangesAsync();
                    ToDoItem insertedItem = await context.ToDoItems.LastOrDefaultAsync();
                    return $"Created item in database with GUID: {insertedItem.Id} from serialized body input.";
                }
            }
            catch (CosmosException ce)
            {
                Console.WriteLine(ce);
                return $"Caught cosmos exception while performing operation: {ce}";
            }
        }
 public ToDoItemsRepository(ToDoItemsContext _context)
 {
     context = _context;
 }
Esempio n. 6
0
 public ToDoItemsController(ToDoItemsContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }