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));
        }
Esempio n. 3
0
        public async Task <TblAuthor> AddAuthors(TblAuthor author)
        {
            var result = await context.TblAuthors.AddAsync(author);

            await context.SaveChangesAsync();

            return(result.Entity);
        }
Esempio n. 4
0
 public void AddAuthor(TblAuthor author)
 {
     if (author == null)
     {
         throw new ArgumentNullException(nameof(author));
     }
     context.TblAuthors.Add(author);
 }
Esempio n. 5
0
        public void DeleteAuthor(TblAuthor author)
        {
            if (author == null)
            {
                throw new ArgumentNullException(nameof(author));
            }

            context.TblAuthors.Remove(author);
        }
Esempio n. 6
0
        public void Create_Author(string Author_Name)
        {
            TblAuthor CreateAuthor = new TblAuthor
            {
                AuthorName = Author_Name
            };

            context.Add(CreateAuthor);
            context.SaveChanges();
        }
Esempio n. 7
0
        public void Delete_Author(int id)
        {
            var DeleteRecord = new TblAuthor {
                AuthorId = id
            };

            context.TblAuthors.Attach(DeleteRecord);
            context.TblAuthors.Remove(DeleteRecord);
            context.SaveChanges();
        }
Esempio n. 8
0
        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"));
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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());
            }
        }
Esempio n. 11
0
        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"));
            }
        }
Esempio n. 12
0
 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));
 }
Esempio n. 13
0
        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"));
            }
        }
Esempio n. 14
0
 void ITblAuthorRep.UpdateAuthor(TblAuthor author)
 {
     throw new NotImplementedException();
 }
Esempio n. 15
0
 public ActionResult AddAuthor(TblAuthor p)
 {
     db.TblAuthor.Add(p);
     db.SaveChanges();
     return(View());
 }