Example #1
0
 private void Load(bool onlyIfExists)
 {
     try
     {
         string filename = PPCConfigurationManager.PlayersPath;
         if (onlyIfExists && !File.Exists(filename))
         {
             return;
         }
         List <Player> players = PlayersDb.Load(filename);
         Players = new ObservableCollection <PlayerItem>(players.Select(x => new PlayerItem
         {
             DCINumber   = x.DCINumber,
             FirstName   = x.FirstName,
             LastName    = x.LastName,
             MiddleName  = x.MiddleName,
             CountryCode = x.CountryCode,
             IsJudge     = x.IsJudge
         }).OrderBy(x => x.FirstName, new EmptyStringsAreLast()));
     }
     catch (Exception ex)
     {
         Logger.Exception("Error while loading player file", ex);
         PopupService.DisplayError("Error while loading player file", ex);
     }
 }
Example #2
0
 private void Save()
 {
     try
     {
         if (!Directory.Exists(Path))
         {
             Directory.CreateDirectory(Path);
         }
         SoldCards soldCards = new SoldCards
         {
             SellerName = SellerName,
             Email      = Email,
             Cards      = Items.Select(x => new SoldCard
             {
                 CardName = x.CardName,
                 Price    = x.Price,
                 Quantity = x.Quantity
             }).ToList()
         };
         string filename = Filename;
         using (XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8))
         {
             writer.Formatting = Formatting.Indented;
             DataContractSerializer serializer = new DataContractSerializer(typeof(SoldCards));
             serializer.WriteObject(writer, soldCards);
         }
     }
     catch (Exception ex)
     {
         Logger.Exception("Error while saving sold cards", ex);
         PopupService.DisplayError("Error while saving sold cards", ex);
     }
 }
Example #3
0
 private void SaveSellers()
 {
     try
     {
         string filename = PPCConfigurationManager.CardSellersPath;
         using (XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8))
         {
             writer.Formatting = Formatting.Indented;
             DataContractSerializer serializer = new DataContractSerializer(typeof(CardSellers));
             serializer.WriteObject(writer, _cardSellers);
         }
     }
     catch (Exception ex)
     {
         Logger.Exception("Error saving card sellers file", ex);
         PopupService.DisplayError("Error saving card sellers file", ex);
     }
 }
Example #4
0
 public void DeleteBackupFiles(string savePath)
 {
     // Move backup files into save folder
     try
     {
         string backupPath = CardSellerViewModel.Path;
         foreach (string file in Directory.EnumerateFiles(backupPath))
         {
             string saveFilename = savePath + "cards_" + Path.GetFileName(file);
             File.Move(file, saveFilename);
         }
     }
     catch (Exception ex)
     {
         Logger.Exception("Error", ex);
         PopupService.DisplayError("Error", ex);
     }
 }
Example #5
0
 private void LoadSellers()
 {
     try
     {
         string filename = PPCConfigurationManager.CardSellersPath;
         if (File.Exists(filename))
         {
             using (XmlTextReader reader = new XmlTextReader(filename))
             {
                 DataContractSerializer serializer = new DataContractSerializer(typeof(CardSellers));
                 _cardSellers = (CardSellers)serializer.ReadObject(reader);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Exception("Error loading card sellers file", ex);
         PopupService.DisplayError("Error loading card sellers file", ex);
     }
 }
Example #6
0
        public void Reload()
        {
            string path = CardSellerViewModel.Path;

            if (Directory.Exists(path))
            {
                foreach (string filename in Directory.EnumerateFiles(path, "*.xml", SearchOption.TopDirectoryOnly))
                {
                    try
                    {
                        CardSellerViewModel seller = new CardSellerViewModel(filename);
                        Sellers.Add(seller);
                    }
                    catch (Exception ex)
                    {
                        Logger.Exception($"Error while loading {filename ?? "??"} seller", ex);
                        PopupService.DisplayError($"Error while loading {filename ?? "??"} seller", ex);
                    }
                }
            }
        }
Example #7
0
 private void Save()
 {
     try
     {
         List <Player> players = Players.Select(x => new Player
         {
             DCINumber   = x.DCINumber,
             FirstName   = x.FirstName,
             LastName    = x.LastName,
             MiddleName  = x.MiddleName,
             CountryCode = x.CountryCode,
             IsJudge     = x.IsJudge
         }).ToList();
         PlayersDb.Save(PPCConfigurationManager.PlayersPath, players);
         Load(false); //TODO crappy workaround to reset row.IsNewItem
     }
     catch (Exception ex)
     {
         Logger.Exception("Error while saving player file", ex);
         PopupService.DisplayError("Error while saving player file", ex);
     }
 }
Example #8
0
        private void AddNewSellerNameSelected(string name, string email)
        {
            CardSellerViewModel alreadyExisingSeller = Sellers.FirstOrDefault(x => String.Equals(x.SellerName, name, StringComparison.InvariantCultureIgnoreCase));

            if (alreadyExisingSeller != null)
            {
                Logger.Warning($"A seller with than name '{name}' has already been opened!");
                PopupService.DisplayError(
                    "Warning",
                    $"A seller with than name '{name}' has already been opened! Switching to {name}",
                    () => SelectedSeller = alreadyExisingSeller);
            }
            else
            {
                // Save sellers
                _cardSellers = _cardSellers ?? new CardSellers();
                CardSeller cardSeller = _cardSellers.Sellers.FirstOrDefault(x => CultureInfo.CurrentCulture.CompareInfo.IndexOf(x.Name, name, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase) >= 0);
                if (cardSeller == null)
                {
                    _cardSellers.Sellers.Add(new CardSeller
                    {
                        Name  = name,
                        Email = email
                    });
                }
                else
                {
                    cardSeller.Email = email;
                }
                SaveSellers();

                // Add seller view model
                CardSellerViewModel newSeller = new CardSellerViewModel(name, email);
                Sellers.Add(newSeller);
                SelectedSeller = newSeller;
            }
        }
        private async Task CreateVoucherAsync()
        {
            // Send mail if client has an email
            try
            {
                IsBusy = true;

                decimal  percentage  = 20;
                DateTime maxValidity = DateTime.Today.AddMonths(1);

                bool byMail = false;
                if (!string.IsNullOrWhiteSpace(Email))
                {
                    await MailSenderBL.SendVoucherMailAsync(Email, FirstName, Sex, percentage, maxValidity);

                    byMail = true;
                }

                if (_isUnsavedNewClient)
                {
                    SaveClient(Client);
                }

                Voucher voucher = new Voucher
                {
                    ClientId        = Client.Id,
                    IssueDate       = DateTime.Now,
                    Percentage      = percentage,
                    ValidityEndDate = maxValidity,
                };
                // Add voucher
                Client.Vouchers = Client.Vouchers ?? new ObservableCollection <Voucher>();
                Client.Vouchers.Add(voucher);
                Client.VoucherModified();
                // Save voucher
                VoucherBL.SaveVoucher(voucher); // !! this will add voucher to client if not already added

                // Purchases cannot be deleted anymore
                foreach (Purchase purchase in Client.Purchases)
                {
                    purchase.IsPurchaseDeletable = false;
                }

                if (byMail)
                {
                    PopupService.DisplayQuestion("Envoi d'un bon d'achat", $"Le bon a bien été envoyé par mail à l'adresse {Email} et sera valable jusqu'au {maxValidity:dd/MM/yyyy}", QuestionActionButton.Ok());
                }
                else
                {
                    PopupService.DisplayQuestion("Envoi d'un bon d'achat", $"Un bon d'achat a été émis et sera valable jusqu'au {maxValidity:dd/MM/yyyy}", QuestionActionButton.Ok());
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
                PopupService.DisplayError("Envoi d'un bon d'achat", $"Erreur lors de l'envoi du mail à {Email} (numéro de client {Client.ClientBusinessId})");
            }
            finally
            {
                IsBusy = false;
            }
        }