예제 #1
0
        /// <see cref="IClientViewModel.OnValidSubmit"/>
        public async void OnValidSubmit()
        {
            try
            {
                // Si contient déjà le même nom de client.
                if (AllClients.Any(x => x.NomClient == NouveauClient.NomClient))
                {
                    string msgWarn = $"Aucun ajout : {NouveauClient.NomClient} existe déjà";
                    NotificationMessage messWarn = new NotificationMessage()
                    {
                        Summary  = "Attention",
                        Detail   = msgWarn,
                        Duration = 3000,
                        Severity = NotificationSeverity.Warning
                    };
                    NotificationService.Notify(messWarn);

                    return;
                }

                // Ajout dans la base de donnée.
                int idClient = await SqlContext.AddClient(NouveauClient.NomClient);

                Client nouveauClient = new Client()
                {
                    IdClient  = idClient,
                    NomClient = NouveauClient.NomClient
                };

                AllClients.Add(nouveauClient);
                await ClientGrid.Reload();

                string message = $"Nouveau client : {nouveauClient.NomClient} ajouté";
                NotificationMessage messNotif = new NotificationMessage()
                {
                    Summary  = "Sauvegarde OK",
                    Detail   = message,
                    Duration = 3000,
                    Severity = NotificationSeverity.Success
                };
                NotificationService.Notify(messNotif);

                Log.Information("CLIENT - " + message);

                NouveauClient = new ClientValidation();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "ClientViewModel - OnValidSubmit");
            }
        }