Esempio n. 1
0
        public void Import()
        {
            try
            {
                UploadedFileBase uploadedFile;
                if (_isNational)
                {
                    uploadedFile = new UploadedFileNational(_nationalCommunity.Id, _dbContext, _request.FilePath);
                }
                else
                {
                    uploadedFile = new UploadedFileCluster(_cluster.Id, _dbContext, _request.FilePath);
                }

                _logger.LogEnd("Please wait while loading individuals. This might take a while...");
                var individuals = uploadedFile.SerializeIndividuals();
                _logger.LogEnd("Ok." + individuals.Count + " individuals found.");
                _logger.Log("Importing " + individuals.Count + " into SRP database...");
                _dbContext.Individuals.AddRange(individuals);
                _dbContext.SaveChanges();
                _logger.LogEnd("Done");
            }
            catch (InvalidOperationException e)
            {
                _logger.LogEnd("Error: **** " + e.Message + " ****");
            }
        }
Esempio n. 2
0
        protected long?GetFocusNeighborhood(long localityId, string focusNeighborhoodName)
        {
            if (string.IsNullOrEmpty(focusNeighborhoodName))
            {
                return(null);
            }
            var foc = DbContext.Subdivisions.FirstOrDefault(f => f.LocalityId == localityId && f.Name == focusNeighborhoodName);

            if (foc == null)
            {
                foc = new Subdivision()
                {
                    Name                 = focusNeighborhoodName,
                    CreatedTimestamp     = DateTime.Now,
                    LastUpdatedTimestamp = DateTime.Now,
                    LocalityId           = localityId
                };
                DbContext.Subdivisions.Add(foc);
                DbContext.SaveChanges();
            }

            return(foc.Id);
        }