Пример #1
0
        /// <summary>
        /// Uploads new donations to FirmaEvent table
        /// </summary>
        /// <param name="donations"></param>
        public static void UploadCompanyDonations(Donations donations)
        {
            foreach (var companyDonations in donations.GetDonations())
            {
                var donor = companyDonations.Key;

                Firma firma = null;
                try
                {
                    firma = Firma.FromIco(donor.CompanyId);
                }
                catch (Exception)
                {
                }

                if (firma is null)
                {
                    Console.WriteLine($"Chybějící firma v db - ICO: {donor.CompanyId}, nazev: {donor.Name}");
                    continue;
                }

                var firmaEvents = firma.Events(ev => ev.Type == (int)FirmaEvent.Types.Sponzor).ToList();

                foreach (var donation in companyDonations.Value)
                {
                    var eventToRemove = firmaEvents.Where(oe => oe.AddInfoNum == donation.Amount &&
                                                          oe.Description == donation.ICO &&
                                                          oe.DatumOd.HasValue &&
                                                          oe.DatumOd.Value.Year == donation.Date.Year).FirstOrDefault();
                    if (eventToRemove is null)
                    {
                        // add event
                        var newEvent = new FirmaEvent()
                        {
                            AddInfo     = NormalizePartyName(donation.Party, donation.ICO),
                            DatumOd     = donation.Date,
                            AddInfoNum  = donation.Amount,
                            Description = donation.ICO,
                            Zdroj       = _zdroj,
                            Note        = donation.Description,
                            Type        = (int)FirmaEvent.Types.Sponzor
                        };
                        firma.AddOrUpdateEvent(newEvent, _user, checkDuplicates: false);
                    }
                    else
                    {
                        firmaEvents.Remove(eventToRemove);
                    }
                }
            }
        }