public async Task <ActionResult <Family> > AddAFamily([FromBody] Family family) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { IList <Family> filteredFamilies = await familyService.GetFamiliesAsync(); IList <Family> families = filteredFamilies.Where(f => f.StreetName.Equals(family.StreetName, StringComparison.OrdinalIgnoreCase) && f.HouseNumber == family.HouseNumber).ToList(); if (!families.Any()) { await familyService.AddFamilyAsync(family); return(Created($"/streetname={family.StreetName}&housenumber={family.HouseNumber}", family)); } return(null); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public async Task <IActionResult> Post(int businessId, [FromBody] string familyName) { string email = User.Identity.Name; await familyService.AddFamilyAsync(businessId, familyName, email); return(Ok()); }
public async Task <ActionResult> AddFamily([FromBody] Family family) { try { await familyService.AddFamilyAsync(family); return(Ok()); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public async Task <ActionResult <Family> > AddFamily([FromBody] Family family) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Family added = await familyService.AddFamilyAsync(family); return(Created($"/{added.StreetName+added.HouseNumber}", added)); // return newly added to-do, to get the auto generated id } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public async Task <ActionResult <Family> > AddFamily([FromBody] Family family) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Family toAdd = await familyService.AddFamilyAsync(family); return(Created($"/{toAdd}", toAdd)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public async Task <ActionResult> AddFamily([FromBody] Family family) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Family added = await _familyService.AddFamilyAsync(family); return(Ok(added)); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public async Task <ActionResult <Family> > AddAFamily([FromBody] Family family) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await familyService.AddFamilyAsync(family); return(Created($"/streetname={family.StreetName}&housenumber={family.HouseNumber}", family)); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public async Task <ActionResult <Family> > AddFamilyAsync([FromBody] Family family) { try { var newFamily = await familyService.AddFamilyAsync(family); return(StatusCode(201, newFamily)); } catch (Exception e) { if (e.Message == "Family already exists") { return(BadRequest(e.Message)); } else { return(StatusCode(500, e.Message)); } } }