示例#1
0
 public int AddAuthor ( Author author)
 {
     DbContext.Authors.Add(author);
     try
     {
         DbContext.SaveChanges();
         return author.ID;
     }
     catch(Exception ex)
     {
         return -1;
     }
 }
        public ActionResult edit(Author author)
        {
            ViewBag.MainNav = Navigator.Main.AUTHOR;

            if (ModelState.IsValid)
            {
                int new_id = authorService.UpdateAuthor(author);

                if (new_id > 0)
                {
                    TempData["SuccessMessage"] = "Author Updated Successfully";
                    return RedirectToAction("Edit", new { id = new_id });
                }
                else
                    TempData["ErrorMessage"] = "Author Failed To Update";
            }
            return View();
        }
示例#3
0
        public int UpdateAuthor ( Author author)
        {
            Author A = DbContext.Authors.Where(a => a.ID == author.ID).FirstOrDefault();

            if (A == null)
                return -1;

            A.FullName = author.FullName;
            A.FullNameAr = author.FullNameAr;

            try
            {
                DbContext.SaveChanges();
                return A.ID;
            }
            catch(Exception ex)
            {
                return -1;
            }
           
        }