public async Task <ActionResult <AuthorBiography> > PostAuthorBiography(AuthorBiography authorBiography) { _context.AuthorBiographies.Add(authorBiography); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAuthorBiography", new { id = authorBiography.AuthorBiographyId }, authorBiography)); }
public async Task <IActionResult> Edit(int id, [Bind("AuthorBiographyId,Biography,DateOfBirth,PlaceOfBirth,Nationality,City,AuthorId")] AuthorBiography authorBiography) { if (id != authorBiography.AuthorBiographyId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(authorBiography); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorBiographyExists(authorBiography.AuthorBiographyId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Authors, "AuthorId", "Email", authorBiography.AuthorId); return(View(authorBiography)); }
public async Task <IActionResult> PutAuthorBiography(int id, AuthorBiography authorBiography) { if (id != authorBiography.AuthorBiographyId) { return(BadRequest()); } _context.Entry(authorBiography).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorBiographyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Details(int id) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:61725"); HttpResponseMessage response = client.GetAsync("/api/authorbiography/" + id).Result; string stringData = response.Content.ReadAsStringAsync().Result; AuthorBiography data = JsonConvert.DeserializeObject<AuthorBiography>(stringData); return View(data); }
public ActionResult Create(AuthorBiography author) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:61725"); string stringData = JsonConvert.SerializeObject(author); var contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("/api/authorbiography", contentData).Result; ViewBag.Message = response.Content.ReadAsStringAsync().Result; return RedirectToAction("Index"); }
public async Task <IActionResult> Create([Bind("AuthorBiographyId,Biography,DateOfBirth,PlaceOfBirth,Nationality,City,AuthorId")] AuthorBiography authorBiography) { if (ModelState.IsValid) { _context.Add(authorBiography); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Authors, "AuthorId", "Email", authorBiography.AuthorId); return(View(authorBiography)); }
private static void OneToOneRelationship(EFCoreRelationshipsExamplesDbContext context) { var author = new Author { Name = "Robert Cecil Martin" }; context.Add(author); context.SaveChanges(); var authorBiography = new AuthorBiography { AuthorId = author.Id, PlaceOfBirth = "Palo Alto - California" }; context.Add(authorBiography); context.SaveChanges(); }
public async Task <ActionResult <AuthorBiography> > PostAuthorBiography(AuthorBiography authorBiography) { _context.AuthorBiographies.Add(authorBiography); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (AuthorBiographyExists(authorBiography.AuthorBiographyId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetAuthorBiography", new { id = authorBiography.AuthorBiographyId }, authorBiography)); }