Esempio n. 1
0
        private string ShowTaxes(IEnumerable <string> enumerable)
        {
            var          date         = DateTime.Parse(enumerable.Skip(1).FirstOrDefault());
            ScheduledTax scheduledTax = null;

            using (var context = new ScheduledTaxContext())
            {
                scheduledTax = context.ScheduledTaxes.Where(x => x.Municipality == enumerable.First() &&
                                                            x.From <= date && x.To >= date)
                               .OrderBy(x => x.To - x.From).SingleOrDefault();
            }

            return(scheduledTax != null ?
                   $"{scheduledTax.Municipality} tax rate is {scheduledTax.Rate} scheduled {scheduledTax.TaxType} from {scheduledTax.From} to {scheduledTax.To}"
                : $"No entry with parameters {enumerable.First()} and {date}");
        }
Esempio n. 2
0
        private string Insert(IEnumerable <string> enumerable)
        {
            using (var context = new ScheduledTaxContext())
            {
                context.ScheduledTaxes.Add(
                    new ScheduledTax
                {
                    ScheduledTaxId = Guid.NewGuid(),
                    Municipality   = enumerable.FirstOrDefault(),
                    TaxType        = enumerable.Skip(1).FirstOrDefault(),
                    Rate           = double.Parse(enumerable.Skip(2).FirstOrDefault()),
                    From           = DateTime.Parse(enumerable.Skip(3).FirstOrDefault()),
                    To             = DateTime.Parse(enumerable.Skip(4).FirstOrDefault())
                });

                context.SaveChanges();
            }

            return("Operation successful");
        }
Esempio n. 3
0
        private string Import(IEnumerable <string> enumerable)
        {
            if (File.Exists(enumerable.First()))
            {
                return($"File not exist in path \"{enumerable.First()}\"");
            }

            IEnumerable <ScheduledTax> records = null;

            using (var reader = new StreamReader(enumerable.First()))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    records = csv.GetRecords <ScheduledTax>();
                }

            using (var context = new ScheduledTaxContext())
            {
                context.ScheduledTaxes.AddRange(records);
                context.SaveChanges();
            }

            return("Operation successful");
        }