예제 #1
0
        public async Task <ActionResult <TaxLiabilityToEditDTO> > EditTaxLiability(int id,
                                                                                   [FromBody] TaxLiabilityToEditDTO taxLiabilityToEditDto)
        {
            if (id != taxLiabilityToEditDto.Id)
            {
                return(BadRequest(new ApiResponse(400, "You lose:)")));
            }

            var email = User.RetrieveEmailFromPrincipal();

            await _taxLiabilitiesService.UpdateUsersSurtaxId(email, taxLiabilityToEditDto.SurtaxId);


            await _taxLiabilitiesService.UpdateTaxLiability1(email, taxLiabilityToEditDto);


            return(NoContent());
        }
        public async Task UpdateTaxLiability1(string email,
                                              TaxLiabilityToEditDTO taxLiabilityToEditDto)
        {
            var user = await _context.AppUsers.Where(ap => ap.Email == email)
                       .FirstOrDefaultAsync();

            var taxLiability = await _context.TaxLiabilities
                               .Include(t => t.Surtax)
                               .Where(t => t.Email == email)
                               .FirstOrDefaultAsync();

            var surtax = await _context.Surtaxes.Where(s => s.Id == user.SurtaxId)
                         .FirstOrDefaultAsync();

            decimal f       = 100;
            decimal?basket4 = await TotalNetProfit(email);

            decimal?basket5 = (12 / f) * basket4;

            taxLiability.SurtaxId    = surtax.Id;
            taxLiability.Year        = DateTime.Now.Year;
            taxLiability.Email       = email;
            taxLiability.GrossProfit = basket4;

            if (basket4.HasValue && basket4 > 0)
            {
                taxLiability.CapitalGainsTax = basket5;
            }
            else
            {
                taxLiability.CapitalGainsTax = 0;
            }

            if (basket4.HasValue && basket4 > 0)
            {
                taxLiability.SurtaxAmount = (surtax.Amount / f) * basket5;
            }
            else
            {
                taxLiability.SurtaxAmount = 0;
            }

            if (basket4.HasValue && basket4 > 0)
            {
                taxLiability.TotalTaxLiaility = basket5 + taxLiability.SurtaxAmount;
            }
            else
            {
                taxLiability.TotalTaxLiaility = 0;
            }

            if (basket4.HasValue && basket4 > 0)
            {
                taxLiability.NetProfit = basket4 - taxLiability.TotalTaxLiaility;
            }
            else
            {
                taxLiability.NetProfit = 0;
            }

            _context.Entry(taxLiability).State = EntityState.Modified;
            await _context.SaveChangesAsync();
        }