public async Task <ActionResult <Model.PhoneBook> > PostPhoneBook(Model.PhoneBook phoneBook) { _context.PhoneBooks.Add(phoneBook); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPhoneBook", new { id = phoneBook.Id }, phoneBook)); }
public async Task <IActionResult> PutPhoneBook(int id, Model.PhoneBook phoneBook) { if (id != phoneBook.Id) { return(BadRequest()); } _context.Entry(phoneBook).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhoneBookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public int Add(string department, string telnumber, string seconddepartment, string campus) { Model.PhoneBook model = new Model.PhoneBook(); model.Department = department; model.SecondDepartment = seconddepartment; model.Campus = campus; model.TelNumber = telnumber; return(dal.Add(model)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Model.PhoneBook phoneBook) { if (ModelState.IsValid) { await PhoneBookRequestService.PostPhoneBookAsync(phoneBook); return(RedirectToAction(nameof(Index))); } return(View(phoneBook)); }
// GET: Entries by Search public async Task <IActionResult> Index(int id, string searchString) { Model.PhoneBook parentPhoneBook = await PhoneBookRequestService.GetPhoneBookAsync(id); if (parentPhoneBook != null) { ViewBag.PhoneBookId = parentPhoneBook.Id; ViewBag.PhoneBookName = parentPhoneBook.Name; } return(View(await EntriesRequestService.SearchEntriesAsync(id, searchString))); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Model.PhoneBook phoneBook) { if (id != phoneBook.Id) { return(NotFound()); } if (ModelState.IsValid) { phoneBook = await PhoneBookRequestService.PutPhoneBookAsync(phoneBook); return(RedirectToAction(nameof(Index))); } return(View(phoneBook)); }
public static async Task PostPhoneBookAsync(Model.PhoneBook phoneBook) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.PostAsJsonAsync(apiUrl + "/PhoneBooks/", phoneBook); if (!response.IsSuccessStatusCode) { throw new HttpRequestException(response.ToString()); } } }
public int Add(Model.PhoneBook model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [Tel]("); strSql.Append("[Department],[Campus],[TelNumber],[SecondDepartment] )"); strSql.Append(" values ("); strSql.Append("@Department,@Campus,@TelNumber,@SecondDepartment)"); OleDbParameter[] parameters = { new OleDbParameter("@Department", OleDbType.VarChar, 255), new OleDbParameter("@Campus", OleDbType.VarChar, 255), new OleDbParameter("@TelNumber", OleDbType.VarChar, 255), new OleDbParameter("@SecondDepartment", OleDbType.VarChar, 255) }; parameters[0].Value = model.Department; parameters[1].Value = model.Campus; parameters[2].Value = model.TelNumber; parameters[3].Value = model.SecondDepartment; return(SqlHelper.ExecuteNonQuery(strSql.ToString(), parameters)); }
public static async Task <Model.PhoneBook> PutPhoneBookAsync(Model.PhoneBook phoneBook) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.PutAsJsonAsync(apiUrl + "/PhoneBooks/" + phoneBook.Id, phoneBook); if (response.IsSuccessStatusCode) { var data = await response.Content.ReadAsStringAsync(); Model.PhoneBook phonebook = Newtonsoft.Json.JsonConvert.DeserializeObject <Model.PhoneBook>(data); return(phonebook); } else { throw new HttpRequestException(response.ToString()); } } }
public CardsRepository(Model.PhoneBook dataContext) { _dataContext = dataContext; }
public PhoneBookUnitOfWork(string jsonFormattedDataPath) { _jsonFormattedDataPath = jsonFormattedDataPath; _dataContext = new Model.PhoneBook(jsonFormattedDataPath); }