private static void VoegEenContactToe() { string naam, geboortedatum, straatEnNummer, postcode, stadOfGemeente, geslacht, gsm, tel; Console.Write("Naam: "); naam = Console.ReadLine(); Console.Write("Geboorte datum: "); geboortedatum = Console.ReadLine(); Console.Write("Straat en nummer: "); straatEnNummer = Console.ReadLine(); Console.Write("Postcode: "); postcode = Console.ReadLine(); Console.Write("Gemeente of stad: "); stadOfGemeente = Console.ReadLine(); Console.Write("Geslach m/v: "); geslacht = Console.ReadLine(); Console.Write("GSM: "); gsm = Console.ReadLine(); Console.Write("telefoon nummer: "); tel = Console.ReadLine(); Gender gender = Gender.Male; // default value DateTime gbdate = DateTime.Parse(geboortedatum); if (geslacht.Equals("m")) { gender = Gender.Male; } else if (geslacht.Equals("v")) { gender = Gender.Female; } contactManager.AddContact(naam, straatEnNummer, (short.Parse(postcode)), stadOfGemeente, gender, gbdate, tel, gsm); }
public async Task <IActionResult> AddContact([FromBody] Contact model) { if (ModelState.IsValid) { try { SerilogManager.Information("Adding contact details for contact name" + model.FirstName); var contactId = await contactManager.AddContact(model); if (contactId > 0) { return(Ok(contactId)); } else { return(NotFound()); } } catch (Exception ex) { SerilogManager.Error("Getting error in adding contact: " + ex.Message); return(BadRequest()); } } return(BadRequest()); }
// POST: api/Contact public void Post([FromBody] Contact value) { value = new Contact { FirstName = "Abhishek", Id = Guid.NewGuid(), LastName = "bandil" }; _contactManager.AddContact(value); }
public IHttpActionResult AddContact(Contact contact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool status = _contactManager.AddContact(contact); return(CreatedAtRoute("DefaultApi", new { id = contact.Id }, contact)); }
static void Main(string[] args) { string baseAddress = "http://" + Environment.MachineName + ":8000/Service"; ServiceHost host = new ServiceHost(typeof(ContactManager), new Uri(baseAddress)); host.AddServiceEndpoint(typeof(IContactManager), new BasicHttpBinding(), "").Behaviors.Add(new ValidatingBehavior()); host.Open(); Console.WriteLine("Host opened"); ChannelFactory <IContactManager> factory = new ChannelFactory <IContactManager>(new BasicHttpBinding(), new EndpointAddress(baseAddress)); IContactManager proxy = factory.CreateChannel(); Console.WriteLine("Test 1: adding a successful contract"); string id = proxy.AddContact(new Contact { Name = "John Doe", Age = 30, Email = "*****@*****.**" }); Console.WriteLine(" ==> Contact id: {0}", id); Console.WriteLine(); Console.WriteLine("Test 2: missing name"); ExpectFaultOfString(delegate { proxy.AddContact(new Contact { Name = null, Age = 30, Email = "*****@*****.**" }); }); Console.WriteLine(); Console.WriteLine("Test 3: empty name"); ExpectFaultOfString(delegate { proxy.AddContact(new Contact { Name = "", Age = 30, Email = "*****@*****.**" }); }); Console.WriteLine(); Console.WriteLine("Test 4: negative age"); ExpectFaultOfString(delegate { proxy.AddContact(new Contact { Name = "John Doe", Age = -1, Email = "*****@*****.**" }); }); Console.WriteLine(); Console.WriteLine("Test 5: very high age"); ExpectFaultOfString(delegate { proxy.AddContact(new Contact { Name = "John Doe", Age = 400, Email = "*****@*****.**" }); }); Console.WriteLine(); Console.WriteLine("Test 6: missing e-mail"); ExpectFaultOfString(delegate { proxy.AddContact(new Contact { Name = "John Doe", Age = 30, Email = null }); }); Console.WriteLine(); Console.WriteLine("Test 7: invalid e-mail"); ExpectFaultOfString(delegate { proxy.AddContact(new Contact { Name = "John Doe", Age = 30, Email = "abcdef" }); }); Console.WriteLine(); }
public async Task <IActionResult> Contactus(Contact contact) { if (ModelState.IsValid) { await _contactManager.AddContact(contact); return(Content("Done")); } string name = contact.Name; return(Content(name)); }
public IActionResult Create(Contact contact) { try { _contactManager.AddContact(contact); return(Ok()); } catch (Exception ex) { //_logger.LogError(ex.Message); return(BadRequest(Util.ErrorResponse.FormatResponse("Something went wrong!", ex.Message))); } }
// POST: api/Contact public IHttpActionResult Post([FromBody] Contact value) { try { _contactManager.AddContact(value); return(Ok()); } catch (Exception ex) { //Added Logger here. //Also we can handle exception in Exception Filter return(InternalServerError()); } }
public async Task <ActionResult <Models.Contact> > SaveContact([FromBody] Models.Contact contact) { var UserId = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value; if (contact.Id > 0) { await contactManager.UpdateContact(contact); } else { contact.IsActive = true; contact.CreatedBy = UserId; contact.CreatedOn = DateTime.Now; contact.UserId = UserId; await contactManager.AddContact(contact); } return(Ok(new { ReturnMessage = "Contact saved successfully", IsSuccess = true, Data = contact })); }
public ActionResult AddContact(Guid contactPersonId) { _contactManager.AddContact(PersonId, contactPersonId); return(Ok()); }