public async Task <ActionResult <AdresModel> > PostAdres(AdresModel model) { var validation = await new AdresValidator().ValidateAsync(model); if (!validation.IsValid) { return(ValidationProblem(validation.ToString())); } var id = await Service.CreateAdres(model); return(CreatedAtAction(nameof(Get), new { id })); }
public async Task <ActionResult> PutAdres(AdresModel model) { var validation = await new AdresValidator().ValidateAsync(model); if (!validation.IsValid) { return(ValidationProblem(validation.ToString())); } if (await Service.UpdateAdres(model)) { return(Ok()); } else { return(NotFound()); } }
public async Task <int> CreateAdres(AdresModel model) { var adres = new Adres { AdresRegel1 = model.AdresRegel1, AdresRegel2 = model.AdresRegel2, Gemeente = model.Gemeente, Huisnummer = model.Huisnummer, HuisnummerToevoeging = model.HuisnummerToevoeging, Land = model.Land, PostCode = model.PostCode, Straat = model.Straat }; Db.Adressen.Add(adres); await Db.SaveChangesAsync(); return(adres.Id); }
public void TestNederlandsePostcodes() { var adres = new AdresModel { Land = "nederland", PostCode = "12345" }; validator.ShouldHaveValidationErrorFor(a => a.PostCode, adres); adres.PostCode = "1234ab"; validator.ShouldNotHaveValidationErrorFor(a => a.PostCode, adres); adres.PostCode = "1234 ab"; validator.ShouldNotHaveValidationErrorFor(a => a.PostCode, adres); adres.PostCode = "1234Ab"; validator.ShouldNotHaveValidationErrorFor(a => a.PostCode, adres); adres.PostCode = "12ab34"; validator.ShouldHaveValidationErrorFor(a => a.PostCode, adres); adres.PostCode = ""; validator.ShouldHaveValidationErrorFor(a => a.PostCode, adres); adres.PostCode = null; validator.ShouldHaveValidationErrorFor(a => a.PostCode, adres); }
public async Task <bool> UpdateAdres(AdresModel model) { var adres = await Db.Adressen.FindAsync(model.Id); if (adres == null) { return(false); } adres.AdresRegel1 = model.AdresRegel1; adres.AdresRegel2 = model.AdresRegel2; adres.Gemeente = model.Gemeente; adres.Huisnummer = model.Huisnummer; adres.HuisnummerToevoeging = model.HuisnummerToevoeging; adres.Land = model.Land; adres.PostCode = model.PostCode; adres.Straat = model.Straat; await Db.SaveChangesAsync(); return(true); }