Exemplo n.º 1
0
        public ActionResult FileUpload(HttpPostedFileBase uploadFile)
        {
            if (uploadFile != null && uploadFile.ContentLength > 0)
            {
                _logger.Info("Deserializing file object");
                var municipalitityList = FileReader.DeserializeXmlFileToObject <MunicipalitityList>(uploadFile.InputStream);
                foreach (var municipalitity in municipalitityList.Municipalities)
                {
                    _logger.Info($"Managing Municipalitity { municipalitity.Name }");
                    //check for unique
                    var existingItem = _repository.GetAllItems().FirstOrDefault(a => a.Name == municipalitity.Name);
                    if (existingItem != default(Municipality))
                    {
                        _logger.Info("Municipalitity already exists on database");
                        continue;
                    }

                    _logger.Info("Adding new Municipalitity");
                    _repository.AddOrUpdate(municipalitity);
                }
            }

            return(RedirectToAction("Index"));
        }
 public IEnumerable <MunicipalityTax> Get(string name)
 {
     _logger.Info($"Getting Municipality Taxes by name: {name}.");
     return(_municipalityTaxesService.GetTaxes(name));
 }