Ejemplo n.º 1
0
 private static async Task<Client> _saveNewClient(Client client, ResotelContext ctx)
 {
     ctx.Clients.Add(client);
     await ctx.SaveChangesAsync();
     Client savedClient = client;
     return savedClient;
 }
Ejemplo n.º 2
0
        private static async Task<Client> _editClient(Client client, ResotelContext ctx)
        {
            Client editedClient = await ctx.Clients.FirstOrDefaultAsync(cl => cl.Id == client.Id);

            // a client only has bookings as reference type properties, and none of them will get changed while we edit the client.
            // so lets make sur entity knows this
            foreach(Booking booking in client.Bookings)
            {
                Booking trackedBooking = await ctx.Bookings
                    .Include(b => b.Dates)
                    .FirstOrDefaultAsync(b => b.Id == booking.Id);
                ctx.Entry(trackedBooking).State = EntityState.Unchanged;
            }

            // update all non reference properties
            ctx.Entry(editedClient).State = EntityState.Modified;
            ctx.Entry(editedClient).CurrentValues.SetValues(client);
            await ctx.SaveChangesAsync();
            return editedClient;
        }
Ejemplo n.º 3
0
 private static async Task<Booking> _saveBooking(Booking booking, ResotelContext ctx, DbContextTransaction transaction)
 {
     await ctx.SaveChangesAsync();
     transaction.Commit();
     return booking;
 }