Ejemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "Id,Name,Year,Publisher,Price")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName")] Author author)
        {
            if (ModelState.IsValid)
            {
                db.Authors.Add(author);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
Ejemplo n.º 3
0
 public ActionResult CategoryEditForm(Category category)
 {
     if (ModelState.IsValid)
     {
         if (category.Id <= 0)
         {
             dc.Categories.Add(category);
         }
         else
         {
             dc.Entry(category).State = EntityState.Modified;
         }
         dc.SaveChanges();
         return(RedirectToAction("CategoryListForm"));
     }
     return(View(category));
 }
Ejemplo n.º 4
0
        public static string CreateBook(BookViewModel bookViewModel)
        {
            try
            {
                using (AlphaBookContext dc = new AlphaBookContext())
                {
                    var category = dc.Categories.Where(x => x.Id == bookViewModel.CategoryId).FirstOrDefault();
                    var book     = new Book
                    {
                        Category  = category,
                        Name      = bookViewModel.Name,
                        Price     = bookViewModel.Price,
                        Publisher = bookViewModel.Publisher,
                        Year      = bookViewModel.Year
                    };
                    List <Author> authors = new List <Author>();
                    var           test    = dc.Authors.Where(x => bookViewModel.AuthorId.Contains(x.Id)).ToList();

                    //foreach (var deg in bookViewModel.AuthorId)
                    //{
                    //    authors.Add(new Author { Id = deg });
                    //    //var findAuthor = dc.Authors.Find(deg);
                    //    //authors.Add(findAuthor);
                    //}
                    book.Authors = test;
                    dc.Books.Add(book);

                    dc.SaveChanges();
                    string message = "Kayıt Başarılı";
                    return(message);
                }
            }
            catch (Exception en)
            {
                return(en.ToString());
            }
        }