Esempio n. 1
0
        public AutoGarage getUserGarage()
        {
            _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            if (_context.Garage.Find(User.Claims.FirstOrDefault().Value.ToString()) == null)
            {
                AutoGarage newGarage = new AutoGarage {
                    AUTO = new List <Auto>(), Compare = new List <Auto>()
                };

                string xmlData = ConvertObjectToXMLString(newGarage);

                var userGarage = new Garage {
                    UserOid = User.Claims.FirstOrDefault().Value.ToString(), UserGarage = xmlData
                };

                _context.Add(userGarage);

                _context.SaveChanges();
            }

            var garage = _context.Garage.AsNoTracking().SingleOrDefault(m => m.UserOid == User.Claims.FirstOrDefault().Value.ToString());

            return(ConvertXmlStringtoObject <AutoGarage>(garage.UserGarage.ToString()));
        }
Esempio n. 2
0
        public async Task AddCSV(List <IFormFile> csvFiles)
        {
            _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            _context.Database.ExecuteSqlCommand("TRUNCATE table TEMP_AUTO");

            foreach (var file in csvFiles)
            {
                if (file.Length > 0)
                {
                    var reader = new StreamReader(file.OpenReadStream());

                    var csv = new CsvReader(reader);

                    csv.Configuration.HasHeaderRecord = false;

                    csv.Configuration.Delimiter = ",";

                    csv.Configuration.MissingFieldFound = null;

                    while (csv.Read())
                    {
                        TempAuto record = csv.GetRecord <TempAuto>();

                        _context.Add(record);

                        _context.SaveChanges();
                    }

                    _context.Database.ExecuteSqlCommand("LoadData");

                    await _service.UploadFileAsync(file, importcsv);

                    await _serviceBlob.UploadFile(file, csvContainer);
                }
            }
        }