Ejemplo n.º 1
0
        public async Task <Nace> createNace(Nace nace)
        {
            await db.Nace.AddAsync(nace);

            db.SaveChanges();
            return(nace);
        }
 public ActionResult NaceGridViewPartialUpdate(Nace item)
 {
     using (var db = new InnosixEntities())
     {
         var model = db.Nace;
         if (ModelState.IsValid)
         {
             try
             {
                 var modelItem = model.FirstOrDefault(it => it.Id == item.Id);
                 if (modelItem != null)
                 {
                     UpdateModel(modelItem);
                     db.SaveChanges();
                 }
             }
             catch (Exception e)
             {
                 ViewData["EditError"] = e.Message;
             }
         }
         else
         {
             ViewData["EditError"] = "Please, correct all errors.";
         }
         return(PartialView("_NaceGridViewPartial", model.ToList()));
     }
 }
        public async Task <ActionResult <Nace> > GetSingle(int id)
        {
            Nace nace = await databaseStore.getNaceById(id);

            if (nace == null)
            {
                return(NotFound());
            }
            return(Ok(nace));
        }
        /// <summary>
        /// Converts a JSON-file on string format to a list of corresponding NaceRegionData objects.
        /// </summary>
        /// <param name="jsonString">A JSON object represented as a string</param>
        /// <param name="attributeName">The name of the datafield. Used to find and set the correct property in NaceRegionObjects</param>
        /// <returns></returns>
        public async Task <List <NaceRegionData> > Convert(string jsonString, string attributeName)
        {
            un = new EuroStatJSONUnNester(jsonString);
            List <NaceRegionData> nrdList = new List <NaceRegionData>();
            List <String>         naceRegionYearFields  = new List <String>();
            List <int>            numberOfItemsInFields = new List <int>();


            if (!un.IsValidDataset())
            {
                return(nrdList);
            }

            List <Region> regions = await databaseStore.getAllRegions();

            List <Nace> naces = await databaseStore.getAllNaces();


            foreach (KeyValuePair <String, String> entry in un.GetValues())
            {
                List <int> totalElementsList = un.GetFields().ConvertAll(field => field.totalElements);
                List <int> indexes           = findIndexesOfFields(int.Parse(entry.Key), totalElementsList);

                int naceId   = indexes[un.GetFieldIndex("nace")];
                int regionId = indexes[un.GetFieldIndex("region")];
                int yearId   = indexes[un.GetFieldIndex("year")];

                string naceCode   = un.GetNaceCode(naceId: naceId);
                string regionCode = un.GetRegionCode(regionId: regionId);
                int    year       = un.GetYear(yearId: yearId);

                double propValue = double.Parse(entry.Value, CultureInfo.InvariantCulture);

                Nace   nace   = naces.Find(nace => nace.naceCode == naceCode);
                Region region = regions.Find(region => region.regionCode == regionCode);

                if (nace != null && region != null)
                {
                    NaceRegionData nrd = new NaceRegionData()
                    {
                        naceId = nace.naceId, regionId = region.regionId, year = year
                    };
                    Type         type = nrd.GetType();
                    PropertyInfo prop = type.GetProperty(attributeName);
                    prop.SetValue(nrd, propValue, null);
                    nrdList.Add(nrd);
                }
            }
            return(nrdList);
        }
 public ActionResult NaceGridViewPartialAddNew(Nace item)
 {
     using (var db = new InnosixEntities())
     {
         var model = db.Nace;
         if (ModelState.IsValid)
         {
             try
             {
                 model.Add(item);
                 db.SaveChanges();
             }
             catch (Exception e)
             {
                 ViewData["EditError"] = e.Message;
             }
         }
         else
         {
             ViewData["EditError"] = "Please, correct all errors.";
         }
         return(PartialView("_NaceGridViewPartial", model.ToList()));
     }
 }