public async Task <Result> InsertInJobTable(Guid jobId, IFormFile requestFile)
        {
            var result = await Result.Try(async() =>
            {
                using (var ms = new MemoryStream())
                {
                    requestFile.CopyTo(ms);
                    var fileBytes      = ms.ToArray();
                    string encodedFile = Convert.ToBase64String(fileBytes);

                    await _context.ImportJobs.AddAsync(new UploadJobsEntity
                    {
                        FileName   = requestFile.FileName,
                        Base64File = encodedFile,
                        JobId      = jobId.ToString(),
                        JobStatus  = JobStatus.NotStarted,
                        // TODO: change here when db supports it
                        // Started = DateTime.Now
                    });

                    await _context.SaveChangesAsync();
                }
            }, exception => LogException(exception, $"Error in method {nameof(InsertInJobTable)}"));

            return(result);
        }
        public async Task <Result> CleanPreviouslyImportedData()
        {
            var result = await Result.Try(async() =>
            {
                _context.ImportedPollingStations.RemoveRange(_context.ImportedPollingStations);
                await _context.SaveChangesAsync();
            }, e => LogException(e));

            return(result);
        }
Beispiel #3
0
        public async Task <Result> RemoveAllPollingStations()
        {
            var result = await Result.Try(async() =>
            {
                _context.PollingStations.RemoveRange(_context.PollingStations);
                await _context.SaveChangesAsync();
            }, e => LogException(e));

            return(result);
        }
Beispiel #4
0
        public async Task <Result> StoreAddress(string county, string locality, string address, double latitude, double longitude)
        {
            return(await Result.Try(async() =>
            {
                await _context.ResolvedAddresses.AddAsync(new Entities.ResolvedAddressEntity()
                {
                    County = county,
                    Locality = locality,
                    Address = address,
                    Latitude = latitude,
                    Longitude = longitude
                });

                await _context.SaveChangesAsync();
            }, (e) =>
            {
                _logger.LogError(e, "Error occurred");
                return "Error occured";
            }));
        }