Exemplo n.º 1
0
        public static async Task UpdateTripAsync(Trip trip)
        {
            var travelContext = new TravelContext();

            travelContext.Update(trip);
            await travelContext.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public static async Task DeleteItemAsync(Item item)
        {
            var travelContext = new TravelContext();

            travelContext.ChecklistItems.Remove(item);
            await travelContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public static async Task UpdateItemAsync(Item item)
        {
            var travelContext = new TravelContext();

            travelContext.Update(item);
            await travelContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public static async Task AddItemAsync(string categoryId, Item item)
        {
            var travelContext  = new TravelContext();
            var targetCategory = await travelContext.Checklists.FindAsync(categoryId);

            targetCategory.Items.Add(item);
            travelContext.Update(targetCategory);
            await travelContext.SaveChangesAsync();
        }
Exemplo n.º 5
0
        public static async Task DeleteChecklistAsync(string id)
        {
            var travelContext = new TravelContext();
            var toDelete      = travelContext.Checklists
                                .Where(c => c.Id.Equals(id))
                                .Include(i => i.Items)
                                .SingleOrDefault();

            travelContext.Checklists.Remove(toDelete);
            await travelContext.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public static async Task DeleteTripAsync(string id)
        {
            var travelContext = new TravelContext();
            var toDelete      = travelContext.Trips
                                .Where(x => x.Id.Equals(id))
                                .Include(y => y.Categories)
                                .ThenInclude(z => z.Items)
                                .SingleOrDefault();

            travelContext.Trips.RemoveRange(toDelete);
            await travelContext.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public static async Task UpdateTripChecklistsAsync(Trip trip)
        {
            var travelContext = new TravelContext();
            var targetTrip    = await travelContext.Trips.FindAsync(trip.Id);

            var targetCategories = await GetItemCategoriesAsync(trip.Id);

            foreach (var category in trip.Categories)
            {
                if (!targetCategories.Any(x => x.Name.Equals(category.Name)))
                {
                    targetTrip.Categories.Add(category);
                }
            }
            travelContext.Update(targetTrip);
            await travelContext.SaveChangesAsync();
        }
Exemplo n.º 8
0
 public static async Task AddTripAsync(Trip trip)
 {
     await using var tripContext = new TravelContext();
     tripContext.Add(trip);
     await tripContext.SaveChangesAsync();
 }