public ActionResult <Owner> Post([FromBody] Owner owner) { try { return(_ownerService.AddNewOwner(owner)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public ActionResult <Owner> Post([FromBody] Owner owner) { try { var Ownerreturn = ownerService.AddNewOwner(owner); return(Created("", Ownerreturn)); } catch (InvalidDataException e) { return(StatusCode(500, e.Message)); } }
public ActionResult <Owner> Post([FromBody] Owner theOwner) { if (string.IsNullOrEmpty(theOwner.OwnerFirstName) || string.IsNullOrEmpty(theOwner.OwnerLastName) || string.IsNullOrEmpty(theOwner.OwnerAddress) || string.IsNullOrEmpty(theOwner.OwnerPhoneNr) || string.IsNullOrEmpty(theOwner.OwnerEmail)) { return(BadRequest("You have not entered all the needed data.")); } try { return(Created("Successfully created the following: ", _ownerService.AddNewOwner(theOwner))); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
private Owner AddNewOwner(string userName) { Console.WriteLine($"You are about to create a new owner {userName}, what is the first name of this owner?"); var firstname = Console.ReadLine(); Console.WriteLine($"Thank you {userName}, what is {firstname}'s last name?"); var lastname = Console.ReadLine(); Console.WriteLine($"Please enter {firstname}, {lastname}'s address:"); var address = Console.ReadLine(); Console.WriteLine($"We are almost done, please enter {firstname} {lastname}'s phonenr:"); var phonenr = Console.ReadLine(); Console.WriteLine($"Lastly we ´need {firstname} {lastname}'s email:"); var email = Console.ReadLine(); Owner theNewOwner = _ownerService.AddNewOwner(firstname, lastname, address, phonenr, email); return(theNewOwner); }