// GET: Contacts/Create public ActionResult Create() { Contact contact = new Contact(); contact.Companies = GetCompanies(); contact.ContactNames = GetContacts(); return View( contact ); }
public async Task HydrateContactsMainViewModel() { string url = string.Empty; try { url = string.Format("{0}/?UserID={1}&Completed=0", API.ContactsAPI, App.Current.Properties["UserId"]); } catch (Exception e) { Debug.WriteLine(e.Message); } var contacts = await API.Get(url); foreach (var contact in contacts) { var c = new Contact { Address = contact.Value<string>("Address"), ContactID = contact.Value<int>("ContactID"), Name = contact.Value<string>("Name"), Notes = contact.Value<string>("Notes"), Phone = contact.Value<string>("Phone"), PicUrl = contact.Value<string>("PicUrl"), }; Contacts.Add(c); } }
public List<Contact> GetAll() { List<Contact> allContacts = new List<Contact>(); if (File.Exists(_fileName)) { using (var reader = File.OpenText(_fileName)) { //read the header line reader.ReadLine(); string inputLine; while ((inputLine = reader.ReadLine()) != null) { var columns = inputLine.Split(','); var contact = new Contact() { ContactID = int.Parse(columns[0]), Name = columns[1], PhoneNumber = columns[2] }; allContacts.Add(contact); } } } return allContacts; }
public void Edit(Contact contact) { var contacts = GetAll(); contacts.RemoveAll(c => c.ContactID == contact.ContactID); contacts.Add(contact); WriteFile(contacts); }
public void Add(Contact contact) { if (_contacts.Any()) contact.ContactId = _contacts.Max(c => c.ContactId) + 1; else contact.ContactId = 1; _contacts.Add(contact); }
public void Add(Contact newContact) { // ternary operator is saying: // if there are any contacts return the max contact id and add 1 to set our new contact id // else set to 1 newContact.ContactID = (_contacts.Any()) ? _contacts.Max(c => c.ContactID) + 1 : 1; _contacts.Add(newContact); }
public static async Task<JObject> PostContact(Contact contact) { var modifiedtask = ModifyContact(contact); var client = new HttpClient(); var data = Newtonsoft.Json.JsonConvert.SerializeObject(contact); var content = new System.Net.Http.StringContent(data, System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(API.ContactsAPI, content); response.EnsureSuccessStatusCode(); return response.Content.ReadAsAsync<JObject>().Result; }
Contact GetContact() { var c = new Contact { Address = PDvm.ProspectDetail.Location, Name = PDvm.ProspectDetail.Name, PicUrl = PDvm.ProspectDetail.PicUrl, ContactID = PDvm.ProspectDetail.UserID }; return c; }
public ActionResult Update(Contact model) { var contact = ContactsCollection.FirstOrDefault(c => c.id == model.id); if (contact != null) { contact.firstname = model.firstname; contact.lastname = model.lastname; } return Json(contact, JsonRequestBehavior.AllowGet); }
public ActionResult UpdateContact(Contact _Contact) { try { ContactsDB.Entry(_Contact).State = System.Data.Entity.EntityState.Modified; ContactsDB.SaveChanges(); return new HttpStatusCodeResult(HttpStatusCode.Accepted); } catch { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } }
public void Add(Contact newContact) { // ternary operator is saying: // if there are any contacts return the max contact id and add 1 to set our new contact id // else set to 1 newContact.ContactID = (GetAll().Any()) ? GetAll().Max(c => c.ContactID) + 1 : 1; var contacts = GetAll(); contacts.Add(newContact); WriteFile(contacts); }
public ActionResult AddContact(Contact _Contact) { try { ContactsDB.Contacts.Add(_Contact); ContactsDB.SaveChanges(); return new HttpStatusCodeResult(HttpStatusCode.Created); // OK = 200 } catch { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } }
private static Contact ModifyContact(Contact contact) { var modifiedContact = new Contact { Address = contact.Address, Name = contact.Name, Notes = contact.Notes, Phone = contact.Phone, PicUrl = contact.PicUrl, ContactID = 1 }; return contact; }
public ActionResult DeleteContact(Contact contact) { // get the id that we passed in //int contactID = int.Parse(Request.Form["ContactID"]); // delete the contact from the repo var repo = Factory.CreateContactRepository(); repo.Delete(contact.ContactID); // get the contacts and go to the Index var contacts = repo.GetAll(); return View("Index", contacts); }
public ActionResult EditContact() { // create a new contact var c = new Contact(); // set the values from the form c.Name = Request.Form["Name"]; c.PhoneNumber = Request.Form["PhoneNumber"]; c.ContactID = int.Parse(Request.Form["ContactID"]); // edit contact in repo var repo = Factory.CreateContactRepository(); repo.Edit(c); return RedirectToAction("Index"); }
public ActionResult AddContact() { // create a contact var c = new Contact(); // get the data from the input fields c.Name = Request.Form["Name"]; c.PhoneNumber = Request.Form["PhoneNumber"]; // create out contact in the repository var repo = Factory.CreateContactRepository(); // add the contact repo.Add(c); return RedirectToAction("Index"); }
public ActionResult AddContact() { //create a contact var c = new Contact(); // get the data from the text boxes c.Name = Request.Form["Name"]; c.PhoneNumber = Request.Form["PhoneNumber"]; //create Fake Db var database = new FakeContactDatabase(); //add the info to db database.Add(c); //nav to home view return RedirectToAction("Index"); }
public void AddNewTest() { var repo = Factory.CreateContactRepository(); var results = repo.GetAll(); var count = results.Count; Contact newContact = new Contact() { Name = "Homer Simpson", PhoneNumber = "555-5055" }; repo.Add(newContact); var newResults = repo.GetAll(); Assert.AreEqual(count + 1, newResults.Count); }
static public string Update(Models.Contact contact, int id) { return("Update Contact SET Name = '" + contact.Name + "', Surname = '" + contact.Surname + "', Birthday = '" + contact.Birthday + "'" + ", Sex = '" + contact.Sex + "' WHERE id = " + id); }
static public string Insert(Models.Contact contact) { return("INSERT INTO Contact VALUES('" + contact.Name + "','" + contact.Surname + "', '" + contact.Birthday + "', '" + contact.Sex + "')"); }
public void Post(Models.Contact contact) { NonQuery(Query.Insert(contact)); }
public void Put(Models.Contact contact, int id) { NonQuery(Query.Update(contact, id)); }
public ActionResult Create(Contact model) { model.id = Guid.NewGuid().ToString(); ContactsCollection.Add(model); return Json(model, JsonRequestBehavior.AllowGet); }
public void CreateContactTest() { ContactsRepository target = new ContactsRepository(); Contact contact = new Contact() { UserName = "******", Organization = "BarnumAndBailey", Title = "Clown", Phone = "6661231234" }; target.CreateContact(contact); }
public async static Task<JObject> AddContact(Contact contact) { var result = await API.PostContact (contact); return result; }
public void Edit(Contact contact) { Delete(contact.ContactId); _contacts.Add(contact); }