public async Task <IActionResult> PutTblAuthor(int id, TblAuthor tblAuthor) { if (id != tblAuthor.IdAuthor) { return(BadRequest()); } _context.Entry(tblAuthor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblAuthorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TblAuthor> > PostTblAuthor(TblAuthor tblAuthor) { _context.TblAuthor.Add(tblAuthor); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTblAuthor", new { id = tblAuthor.IdAuthor }, tblAuthor)); }
public async Task <TblAuthor> AddAuthors(TblAuthor author) { var result = await context.TblAuthors.AddAsync(author); await context.SaveChangesAsync(); return(result.Entity); }
public void AddAuthor(TblAuthor author) { if (author == null) { throw new ArgumentNullException(nameof(author)); } context.TblAuthors.Add(author); }
public void DeleteAuthor(TblAuthor author) { if (author == null) { throw new ArgumentNullException(nameof(author)); } context.TblAuthors.Remove(author); }
public void Create_Author(string Author_Name) { TblAuthor CreateAuthor = new TblAuthor { AuthorName = Author_Name }; context.Add(CreateAuthor); context.SaveChanges(); }
public void Delete_Author(int id) { var DeleteRecord = new TblAuthor { AuthorId = id }; context.TblAuthors.Attach(DeleteRecord); context.TblAuthors.Remove(DeleteRecord); context.SaveChanges(); }
public ActionResult SaveAuthor(TblAuthor p) { var getir = db.TblAuthor.Find(p.authorID); getir.authorName = p.authorName; getir.authorSurname = p.authorSurname; getir.authorDetail = p.authorDetail; db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <TblAuthor> Update_Author(TblAuthor author) { var result = await context.TblAuthors .FirstOrDefaultAsync(e => e.AuthorId == author.AuthorId); if (result != null) { result.AuthorName = author.AuthorName; await context.SaveChangesAsync(); return(result); } return(null); }
public ActionResult DeleteConfirmed([Bind(Include = "AuthorId,AuthorName,Description")] TblAuthor tblAuthor) { HttpClient cl = new HttpClient(); cl.BaseAddress = new Uri("http://localhost:5383/Api/Authors/"); cl.DefaultRequestHeaders.Accept.Clear(); cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var resp = cl.DeleteAsync("" + tblAuthor.AuthorId).Result; if (resp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } else { return(View()); } }
CreateEmployee([FromBody] TblAuthor author) { try { if (author == null) { return(BadRequest()); } var createdauthor = await _AuthorRep.AddAuthors(author); return(CreatedAtAction(nameof(GetAuthorss), new { id = createdauthor.AuthorId }, createdauthor)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating new author record")); } }
public ActionResult Edit([Bind(Include = "AuthorId,AuthorName,Description")] TblAuthor tblAuthor) { if (ModelState.IsValid) { HttpClient cl = new HttpClient(); cl.BaseAddress = new Uri("http://localhost:5383/Api/Authors/"); cl.DefaultRequestHeaders.Accept.Clear(); cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); string json = JsonConvert.SerializeObject(tblAuthor); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); var resp = cl.PutAsync("" + tblAuthor.AuthorId, content).Result; if (resp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", tblAuthor.AuthorId)); } } return(View(tblAuthor)); }
public async Task <ActionResult <TblAuthor> > UpdateEmployee(int id, TblAuthor author) { try { if (id != author.AuthorId) { return(BadRequest("Author ID mismatch")); } var authorToUpdate = await _AuthorRep.GetAuthorss(id); if (authorToUpdate == null) { return(NotFound($"Author with Id = {id} not found")); } return(await _AuthorRep.Update_Author(author)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error updating data")); } }
void ITblAuthorRep.UpdateAuthor(TblAuthor author) { throw new NotImplementedException(); }
public ActionResult AddAuthor(TblAuthor p) { db.TblAuthor.Add(p); db.SaveChanges(); return(View()); }