示例#1
0
 private static async Task<Client> _saveNewClient(Client client, ResotelContext ctx)
 {
     ctx.Clients.Add(client);
     await ctx.SaveChangesAsync();
     Client savedClient = client;
     return savedClient;
 }
示例#2
0
 /// <summary>
 /// Save or Update a Client
 /// </summary>
 /// <param name="client">requested client</param>
 /// <returns>The saved Client with its new id, if a new Client is passed</returns>
 public async static Task<Client> Save(Client client)
 {
     Client savedClient = null;
     using (ResotelContext ctx = new ResotelContext())
     {
         if (client.Id == 0)
         {
             savedClient = await _saveNewClient(client, ctx);
         }
         else
         {
             savedClient = await _editClient(client, ctx);
         }
     }
     return savedClient;
 }
示例#3
0
 public Booking()
 {
     Client = new Client();
     OptionChoices = new List<OptionChoice>();
     Rooms = new List<Room>();
     Dates = new DateRange();
     _roomDiscounts = new List<AppliedDiscount>();
     _propertiesValidations = new Dictionary<string, Func<string>> {
         { nameof(Client), _validateClient },
         { nameof(OptionChoices), _validateOptions },
         { nameof(Rooms), _validateRooms },
         { nameof(Dates), _validateDates },
         { nameof(AdultsCount), _validateAdultsCount },
         { nameof(BabiesCount), _validateBabiesCount }
     };
 }
示例#4
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;
        }
示例#5
0
        private void _addClient(object ignore)
        {
            try
            {
                Logger.Log("=Ajout d'un nouveau client=");
                Client newClient = new Client();
                ClientEntity newClientEntity = new ClientEntity(newClient);
                Logger.Log("Ajout d'un nouveau client: Affichage de la fiche client");
                ClientViewModel clientVM = new ClientViewModel(_navigation, newClientEntity);
                _currentEntities.Add(clientVM);
                _currentEntitiesView.MoveCurrentToLast();
            }
            catch (Exception ex)
            {

                Logger.Log(ex);
            }
        }
示例#6
0
 public void AddClient(Client client)
 {
     Client = client;
     client.Bookings.Add(this);
 }