public IActionResult Post([FromBody] Country item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            item.Id = _context.Countries.Count() + 1;
            _context.Countries.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetCountry", new { id = item.Id }, item));
        }
        public static NationalAddress InsertAddressInDb(AddressesContext context, string key = null, NationalAddress request = null)
        {
            var randomAddressRecord = CreateConfigurableAddressRecord(key, request);

            context.NationalAddresses.Add(randomAddressRecord);
            context.SaveChanges();
            return(randomAddressRecord);
        }
Beispiel #3
0
        public static CrossReference InsertCrossReference(AddressesContext context, long uprn, CrossReference record = null)
        {
            if (record == null)
            {
                var fixture = new Fixture();
                record = fixture.Build <CrossReference>()
                         .With(cr => cr.UPRN, uprn)
                         .Create();
            }

            record.UPRN = uprn;
            context.AddressCrossReferences.Add(record);
            context.SaveChanges();

            return(record);
        }
        public static CrossReference InsertCrossReference(AddressesContext context, long uprn, CrossReference record = null)
        {
            var fixture = new Fixture();
            var randomCrossReference = fixture.Build <CrossReference>()
                                       .With(cr => cr.UPRN, uprn)
                                       .Create();

            if (record?.UPRN != null && record.UPRN != 0)
            {
                randomCrossReference.UPRN = record.UPRN;
            }
            if (record?.CrossRefKey != null)
            {
                randomCrossReference.CrossRefKey = record.CrossRefKey;
            }
            if (record?.Code != null)
            {
                randomCrossReference.Code = record.Code;
            }
            if (record?.Name != null)
            {
                randomCrossReference.Name = record.Name;
            }
            if (record?.Value != null)
            {
                randomCrossReference.Value = record.Value;
            }
            if (record?.EndDate != null)
            {
                randomCrossReference.EndDate = record.EndDate;
            }

            context.AddressCrossReferences.Add(randomCrossReference);
            context.SaveChanges();
            return(randomCrossReference);
        }
Beispiel #5
0
        public static NationalAddress InsertAddress(AddressesContext context, string key = null, NationalAddress request = null)
        {
            var fixture             = new Fixture();
            var randomAddressRecord = fixture.Build <NationalAddress>()
                                      .With(a => a.AddressStatus, request?.AddressStatus ?? "Approved Preferred")
                                      .Create();

            if (key != null)
            {
                randomAddressRecord.AddressKey = key;
            }
            if (request?.Postcode != null)
            {
                randomAddressRecord.Postcode        = ReplaceEmptyStringWithNull(request.Postcode);
                randomAddressRecord.PostcodeNoSpace = request.Postcode?.Replace(" ", "");
            }
            if (request?.BuildingNumber != null)
            {
                randomAddressRecord.BuildingNumber = request.BuildingNumber;
            }
            if (request?.Street != null)
            {
                randomAddressRecord.Street = request.Street;
            }
            if (request?.UPRN != null)
            {
                randomAddressRecord.UPRN = request.UPRN;
            }
            if (request?.USRN != null)
            {
                randomAddressRecord.USRN = request.USRN;
            }
            if (request?.UsagePrimary != null)
            {
                randomAddressRecord.UsagePrimary = request.UsagePrimary;
            }
            if (request?.UsageCode != null)
            {
                randomAddressRecord.UsageCode = request.UsageCode;
            }
            if (request?.Gazetteer != null)
            {
                randomAddressRecord.Gazetteer = request.Gazetteer;
            }
            if (request?.NeverExport != null)
            {
                randomAddressRecord.NeverExport = request.NeverExport;
            }
            if (request?.Town != null)
            {
                randomAddressRecord.Town = request.Town;
            }
            if (request?.Street != null)
            {
                randomAddressRecord.Street = request.Street;
            }
            if (request?.PaonStartNumber != null)
            {
                randomAddressRecord.PaonStartNumber = request.PaonStartNumber;
            }
            if (request?.BuildingNumber != null)
            {
                randomAddressRecord.BuildingNumber = ReplaceEmptyStringWithNull(request.BuildingNumber);
            }
            if (request?.UnitNumber != null)
            {
                randomAddressRecord.UnitNumber = request.UnitNumber;
            }
            if (request?.UnitName != null)
            {
                randomAddressRecord.UnitName = ReplaceEmptyStringWithNull(request.UnitName);
            }
            if (request?.Line1 != null)
            {
                randomAddressRecord.Line1 = request.Line1;
            }
            if (request?.Line2 != null)
            {
                randomAddressRecord.Line2 = request.Line2;
            }
            if (request?.Line3 != null)
            {
                randomAddressRecord.Line3 = request.Line3;
            }
            if (request?.Line4 != null)
            {
                randomAddressRecord.Line4 = request.Line4;
            }

            context.NationalAddresses.Add(randomAddressRecord);
            context.SaveChanges();
            return(randomAddressRecord);
        }