internal void Insert(TaxEntry newEntry)
        {
            var oldEntry = _ctx.TaxEntries.Where(te => te.TaxType == newEntry.TaxType && te.StartDate == newEntry.StartDate).FirstOrDefault();

            if (oldEntry != null)
            {
                _ctx.TaxEntries.Remove(oldEntry);
                _ctx.SaveChanges();
            }

            _ctx.TaxEntries.Add(newEntry);
            _ctx.Entry(newEntry.Municipality).State = EntityState.Unchanged; //Municipality is guaranteed to already exist
            _ctx.SaveChanges();
        }
        public async Task <MunicipalityTax> AddMunicipalityTaxes(MunicipalityTax municipalityTax, bool saveToDb = false)
        {
            var municipality = _context.Municapilities.Where(m => m.Name == municipalityTax.MunicipalityName).FirstOrDefault();
            var tax          = Tax.FromMunicipalityTax(municipalityTax);

            if (municipality == null)
            {
                _context.Municapilities.Add(new Municipality {
                    Name = municipalityTax.MunicipalityName
                });
                _context.SaveChanges();
                municipality = _context.Municapilities.Where(m => m.Name == municipalityTax.MunicipalityName).FirstOrDefault();
            }

            tax.MunicipalityId = municipality.Id;

            if (!TaxIsValid(tax))
            {
                throw new Exception("Invalid tax");
            }

            _context.Taxes.Add(tax);
            await _context.SaveChangesAsync();

            municipalityTax.EndDate = tax.EndDate;

            return(municipalityTax);
        }
示例#3
0
 public VatControllers(TaxContext dbContext)
 {
     db = dbContext;
     if (db.Vats.Count() == 0)
     {
         db.Vats.Add(new Vat {
             VatId      = 7,
             EffectDate = DateTime.Now
         });
         db.SaveChanges();
     }
     taxRepo = new Repository(db);
 }
示例#4
0
        public void AddMonth(TaxModel finance)
        {
            var existingRecord = context.Finances.Where(f => f.User.Name == finance.User.Name && f.Month.ToLower() == finance.Month.ToLower()).FirstOrDefault();

            if (existingRecord == null)
            {
                context.Finances.Add(finance);
                context.SaveChanges();
            }
            else
            {
                existingRecord.MonthlyIncome  = finance.MonthlyIncome;
                existingRecord.Medicare       = finance.Medicare;
                existingRecord.SocialSecurity = finance.SocialSecurity;
                context.SaveChanges();
            }
        }
示例#5
0
        public Municipality GetByTitle(string title)
        {
            var returnVal = _ctx.Municipalities.Where(te => te.Title.ToLower() == title.ToLower()).FirstOrDefault();

            if (returnVal != null)
            {
                return(returnVal);
            }
            else
            {
                Municipality newMunicipality = new Municipality {
                    Title = title
                };
                _ctx.Municipalities.Add(newMunicipality);
                _ctx.SaveChanges();

                return(newMunicipality);
            }
        }
示例#6
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }