private async Task <Response> SaveAsnFileToDb(DbFileModel file, CheckUpdateResponseModel checkUpdate)
        {
            try
            {
                if (checkUpdate.HistoryRecordKey == null)
                {
                    throw new CustomException(ResponseCodes.INVALID_PARAMETER, ErrorMessages.BadExternalResponse);
                }

                var parseFile = FileService.ParseCsvAsnDbFile(file.FileData);
                if (parseFile == null || parseFile.Count == 0)
                {
                    throw new CustomException(ResponseCodes.FAILURE, ErrorMessages.FileIsCorruptErrorMessage);
                }

                var convertNetmaskRange =
                    NetMaskConverter.IpV4NetmaskRangeParse(parseFile.Select(s => s.Network).ToList());

                using (IDbService dbService = new DbService(_db).DbServiceInstance)
                {
                    var datesForSave = convertNetmaskRange.
                                       Join(parseFile, ipRange => ipRange.NetMask, csv => csv.Network, (ipRange, csv) =>
                                            new Ipv4AsnBaseRequest
                    {
                        Network = ipRange.NetMask,
                        Cidr    = ipRange.Cidr,
                        AutonomousSystemNumber       = csv.AutonomousSystemNumber,
                        AutonomousSystemOrganization = csv.AutonomousSystemOrganization,
                        MinFirstSegment  = ipRange.MinFirstSegment,
                        MinSecondSegment = ipRange.MinSecondSegment,
                        MinThirdSegment  = ipRange.MinThirdSegment,
                        MinLastSegment   = ipRange.MinLastSegment,
                        MaxFirstSegment  = ipRange.MaxFirstSegment,
                        MaxSecondSegment = ipRange.MaxSecondSegment,
                        MaxThirdSegment  = ipRange.MaxThirdSegment,
                        MaxLastSegment   = ipRange.MaxLastSegment,
                        Md5Sum           = checkUpdate.LastHashValue,
                        // ReSharper disable once PossibleInvalidOperationException
                        HistoryKey = (Guid)checkUpdate.HistoryRecordKey
                    }).ToList();

                    var checkStoredHash = await dbService.GeoLiteIpV4Asn.CreateRange(datesForSave);

                    if (checkStoredHash.ResultCode != ResponseCodes.SUCCESS)
                    {
                        throw new CustomException(checkStoredHash.ResultCode,
                                                  checkStoredHash.Errors.FirstOrDefault()?.ResultMessage);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(new Response());
        }
        private async Task <Response> SaveCityBlocksFileToDb(DbFileModel file, CheckUpdateResponseModel checkUpdate)
        {
            try
            {
                if (checkUpdate.HistoryRecordKey == null)
                {
                    throw new CustomException(ResponseCodes.INVALID_PARAMETER, ErrorMessages.BadExternalResponse);
                }

                var parseFile = FileService.ParseCsvCityBlocksDbFile(file.FileData);
                if (parseFile == null || parseFile.Count == 0)
                {
                    throw new CustomException(ResponseCodes.FAILURE, ErrorMessages.FileIsCorruptErrorMessage);
                }

                var convertNetmaskRange =
                    NetMaskConverter.IpV4NetmaskRangeParse(parseFile.Select(s => s.Network).ToList());

                using (IDbService dbService = new DbService(_db).DbServiceInstance)
                {
                    var datesForSave = convertNetmaskRange.
                                       Join(parseFile, ipRange => ipRange.NetMask, csv => csv.Network, (ipRange, csv) =>
                                            new CityBaseRequest
                    {
                        GeoNameId = csv.GeoNameId,
                        RegisteredCountryGeonameId  = csv.RegisteredCountryGeonameId,
                        RepresentedCountryGeonameId = csv.RepresentedCountryGeonameId,
                        IsAnonymousProxy            = csv.IsAnonymousProxy,
                        IsSatelliteProvider         = csv.IsSatelliteProvider,
                        PostalCode       = csv.PostalCode,
                        Latitude         = csv.Latitude,
                        Longitude        = csv.Longitude,
                        AccuracyRadius   = csv.AccuracyRadius,
                        Network          = ipRange.NetMask,
                        Cidr             = ipRange.Cidr,
                        MinFirstSegment  = ipRange.MinFirstSegment,
                        MinSecondSegment = ipRange.MinSecondSegment,
                        MinThirdSegment  = ipRange.MinThirdSegment,
                        MinLastSegment   = ipRange.MinLastSegment,
                        MaxFirstSegment  = ipRange.MaxFirstSegment,
                        MaxSecondSegment = ipRange.MaxSecondSegment,
                        MaxThirdSegment  = ipRange.MaxThirdSegment,
                        MaxLastSegment   = ipRange.MaxLastSegment,
                        Md5Sum           = checkUpdate.LastHashValue,
                        // ReSharper disable once PossibleInvalidOperationException
                        HistoryKey = (Guid)checkUpdate.HistoryRecordKey
                    }).ToList();

                    var checkStoredHash = await dbService.GeoLiteIpv4City.CreateRange(datesForSave);

                    if (checkStoredHash.ResultCode != ResponseCodes.SUCCESS)
                    {
                        throw new CustomException(checkStoredHash.ResultCode,
                                                  checkStoredHash.Errors.FirstOrDefault()?.ResultMessage);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(new Response());
        }