public ActionResult Calculate([Bind(Exclude = "Id")] TaxInput info) { /*ModelState.Remove("Gross"); * ModelState.Remove("Net"); * ModelState.Remove("Total");*/ /*if ((info.Gross == info.Net) && (info.Net== info.Total) && (info.Total == info.Gross) && info.Gross==null) * { * return View("Index", info); * }*/ if (!ModelState.IsValid) { return(View("Index", info)); } TaxCalculator taxCalculator = new TaxCalculator(); TaxInput outCome = new TaxInput(); if (info.Gross > 0) { info.Net = 0; info.Total = 0; outCome = taxCalculator.getTotalNet(new TaxCalculatorServ(), info); } else if (info.Net > 0) { info.Total = 0; info.Gross = 0; outCome = taxCalculator.getGrossTotal(new TaxCalculatorServ(), info); } else if (info.Total > 0) { info.Net = 0; info.Gross = 0; outCome = taxCalculator.getNetGross(new TaxCalculatorServ(), info); } _context.TaxInputs.Add(outCome); _context.SaveChanges(); return(View("Results", outCome)); }
public IHttpActionResult AddTax([FromBody] TaxInput input) { String email; try { var handler = new JwtSecurityTokenHandler(); var jsonToken = handler.ReadToken(input.Token); var tokenS = handler.ReadToken(input.Token) as JwtSecurityToken; email = tokenS.Claims.First(claim => claim.Type == "email").Value; }catch (Exception e) { return(BadRequest()); } SqlConnection conn = new SqlConnection(); conn.ConnectionString = @"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog = SysIntTax; Integrated Security = True;"; conn.Open(); SqlCommand command = new SqlCommand("UPDATE dbo.Citizens set taxOwed = taxOwed + " + input.Money + " WHERE id = '" + email + "'", conn); command.ExecuteNonQuery(); command.CommandText = "SELECT taxOwed from dbo.Citizens WHERE id = '" + email + "'"; SqlDataReader reader = command.ExecuteReader(); String taxOwedOutput = ""; while (reader.Read()) { var taxOwed = reader["taxOwed"]; taxOwedOutput = taxOwed.ToString(); } conn.Close(); return(Ok(new { statuscode = 200, message = input.Money + " is added to your taxrecord", taxOwed = taxOwedOutput })); }
public TaxInput GetGrossTotal(TaxInput info) { info.Gross = (double)(info.Net * (info.VAT / 100)); info.Total = info.Gross + info.Net; return(info); }
public TaxInput GetTotalNet(TaxInput info) { info.Net = (double)(info.Gross * (100 / info.VAT)); info.Total = info.Gross + info.Net; return(info); }
public TaxInput GetNetGross(TaxInput info) { info.Net = (double)(info.Total * (info.VAT / 100)); info.Gross = info.Total - info.Net; return(info); }
public TaxInput getGrossTotal(ITaxCalculator serv, TaxInput ti) { this._tc = serv; return(this._tc.GetGrossTotal(ti)); }
public TaxInput getTotalNet(ITaxCalculator serv, TaxInput ti) { this._tc = serv; return(this._tc.GetTotalNet(ti)); }