public ActionResult AddTax([FromBody] MunicipalityTax municipalityTax) { if (!ModelState.IsValid) { return(BadRequest("The posted model is invalid")); } municipalityTax.EndDate = endDateService.GetEndDate(municipalityTax.StartDate, municipalityTax.Period); try { municipalityTaxRepository.CreateMunicipalityTax(municipalityTax); } catch (MunicipalityTaxUpdateException e) { return(BadRequest(e.Message)); } return(Ok()); }
private MunicipalityTax ParseMunicipalityTax(string csvLine) { var csvValues = csvLine.Split(",").Select(v => v.Trim()).ToArray(); //Expected format municipality,period,start date,tax if (csvValues.Length != 4) { throw new FormatException("Line did not match the expected format: municipality,period,start date,tax"); } var municipalityTax = new MunicipalityTax(); municipalityTax.Municipality = csvValues[0]; municipalityTax.Period = ParsePeriod(csvValues[1]); municipalityTax.StartDate = ParseStartDate(csvValues[2]); municipalityTax.EndDate = endDateService.GetEndDate(municipalityTax.StartDate, municipalityTax.Period); municipalityTax.Tax = ParseTax(csvValues[3]); return(municipalityTax); }