コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            BookMasterBL objbook = new BookMasterBL();

            try
            {
                BookMaster b = new BookMaster(); //b--->>bookmaster
                b.BookId     = Convert.ToInt32(txtBookId.Text);
                b.BookName   = txtBookName.Text;
                b.BookStatus = Convert.ToString(cmbStatus.SelectedItem);


                objbook.SaveBookMasterdata(b);
                MessageBox.Show("Record is Saved...");
            }

            catch (Exception ex)
            {
                MessageBox.Show("Record is Not Saved...");
                objbook.InserToErrorLog("Book", ex.Message.ToString(), "btnSave_Click");
            }

            finally
            {
            }
        }
コード例 #2
0
ファイル: BookMasterDA.cs プロジェクト: AjayHK1/LMS
        public int DeleteBookMasterdataFromDB(BookMaster objBook)
        {
            int n = 0;

            //spDeleteBookMasterDetails
            try
            {
                SqlCommand cmd = new SqlCommand("spDeleteBookMasterDetails", con.ActiveCon());
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Book_Id", objBook.BookId);
                n = cmd.ExecuteNonQuery();
                n = n > 0 ? 1 : 0;
            }

            catch (Exception ex)
            {
                InsertToErrorLog("BookDA", ex.Message.ToString(), "DeleteBookMasterdataFromDB");
            }

            finally
            {
                con.CloseCon();
            }

            return(n);
        }
コード例 #3
0
ファイル: BookMasterDA.cs プロジェクト: AjayHK1/LMS
        public int SaveBookMasterdataToDB(BookMaster objBook)
        {
            int n = 0;

            try
            {
                SqlCommand cmd = new SqlCommand("spInsBookMasterDetails", con.ActiveCon()); //Constant file
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Book_Id", objBook.BookId);
                cmd.Parameters.AddWithValue("@Book_Name", objBook.BookName);
                cmd.Parameters.AddWithValue("@Book_Status", objBook.BookStatus);
                n = cmd.ExecuteNonQuery();
                n = n > 0 ? 1 : 0;
            }

            catch (Exception ex)
            {
                InsertToErrorLog("BookDA", ex.Message.ToString(), "SaveBookMasterdataToDB");
            }

            finally
            {
                con.CloseCon();
            }

            return(n);
        }
コード例 #4
0
        public async Task <BookMaster> AddBookMaster(BookMaster newBook)
        {
            var addBookResult = await appDbContext.BookMaster.AddAsync(newBook);

            await appDbContext.SaveChangesAsync();

            return(addBookResult.Entity);
        }
コード例 #5
0
        //public class CarViewModel
        //{
        //    public string Car { get; set; }

        //    public List<SelectListItem> Cars { get; } = GetSelectListItems();
        //}
        public ActionResult About()
        {
            //ViewBag.CarsList = GetSelectListItems();//the first Demo

            var model = new BookMaster();                                                           //the third Demo

            model.Publishers  = new SelectList(GetPublishers(), "PublisherId", "PublisherName", 2); //the second Demo
            model.PublisherId = "2";
            ViewBag.Message   = "Your application description page.";
            return(View(model));
        }
コード例 #6
0
        public IActionResult DeleteBook(DeleteBookViewModel bookModel)
        {
            BookMaster bookToDelete      = _bookMasterRepository.GetBook(bookModel.BookId);
            int        deleteSuccessFlag = _bookMasterRepository.DeleteBook(bookToDelete);

            if (deleteSuccessFlag > 0)
            {
                return(RedirectToAction("Index", "Book"));
            }
            ModelState.AddModelError("", "Operation unsuccessful. Book id is not correct.");
            return(View(bookModel));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "BookId,BookName,BookPrice,AuthorID")] BookMaster bookMaster)
        {
            if (ModelState.IsValid)
            {
                _IBookRepository.InsertBook(bookMaster);
                _IBookRepository.Save();
                return(RedirectToAction("Index"));
            }

            ViewBag.AuthID = new SelectList(_IAuthorRepository.GetAuthors(), "AuthorID", "AuthorName", bookMaster.AuthorID);
            return(View(bookMaster));
        }
コード例 #8
0
        public IActionResult UpdateBook(UpdateBookViewModel book)
        {
            BookMaster bookToUpdate      = _bookMasterRepository.GetBook(book.BookMasterId);
            int        updateSuccessFlag = _bookMasterRepository.DeleteBook(bookToUpdate);

            if (updateSuccessFlag > 0)
            {
                return(RedirectToAction("Index", "Book"));
            }
            ModelState.AddModelError("", "Operation not successfull");
            return(RedirectToAction("Update", "Book"));
        }
コード例 #9
0
        // GET: BookMasters/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookMaster bookMaster = _IBookRepository.GetBookByID(id);

            if (bookMaster == null)
            {
                return(HttpNotFound());
            }
            return(View(bookMaster));
        }
コード例 #10
0
        public ActionResult EditPopup(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookMaster bookMaster = _IBookRepository.GetBookByID(id);

            if (bookMaster == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AuthID = new SelectList(_IAuthorRepository.GetAuthors(), "AuthorID", "AuthorName", bookMaster.AuthorID);
            return(PartialView("_BookEdit", bookMaster));
        }
コード例 #11
0
ファイル: BookMasterBL.cs プロジェクト: AjayHK1/LMS
        public int UpdateBookMasterData(BookMaster b)
        {
            int           n       = 0;
            IBookMasterDA objBook = new BookMasterDA();

            try
            {
                n = Convert.ToInt32(objBook.UpdateBookMasterdataToDB(b));
            }

            catch (Exception ex)
            {
                objBook.InsertToErrorLog("BookBL", ex.Message.ToString(), "UpdateBookMasterData");
            }

            return(n);
        }
コード例 #12
0
        public async Task <ActionResult <BookMaster> > AddBookMaster(BookMaster newBook)
        {
            try
            {
                if (newBook == null)
                {
                    return(BadRequest());
                }
                var CreatedBook = await bookMasterRepository.AddBookMaster(newBook);

                return(CreatedAtAction(nameof(GetBookMaster), new { id = CreatedBook.BookMasterID }, CreatedBook));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error to add Book Details."));
            }
        }
コード例 #13
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            BookMasterBL objbook = new BookMasterBL();

            try
            {
                BookMaster b = new BookMaster();
                b.BookId = Convert.ToInt32(txtBookId.Text);


                objbook.DeleteBookMasterData(b);
                MessageBox.Show("Record is Deleted...");
            }

            catch (Exception ex)
            {
                MessageBox.Show("Record is Not Deleted...");
                objbook.InserToErrorLog("Book", ex.Message.ToString(), "btnDelete_Click");
            }
        }
コード例 #14
0
        public IActionResult Update(UpdateBookViewModel book)
        {
            BookMaster bookToUpdate = _bookMasterRepository.GetBook(book.BookMasterId);

            if (bookToUpdate != null)
            {
                var updateBookViewModel = new UpdateBookViewModel
                {
                    InfoFetched      = true,
                    Title            = bookToUpdate.Title,
                    Author           = bookToUpdate.Author,
                    BookMasterId     = bookToUpdate.BookMasterId,
                    ShortDescription = bookToUpdate.ShortDescription,
                    LongDescription  = bookToUpdate.LongDescription
                };
                ModelState.AddModelError("", "Sorry!Feature not implemented yet.");
                return(View(updateBookViewModel));
            }
            ModelState.AddModelError("", "Operation unsuccessful. Book id is not correct.");
            return(View(book));
        }
コード例 #15
0
 public IActionResult AddBook(AddBookViewModel book)
 {
     if (ModelState.IsValid)
     {
         int        userId    = Int32.Parse(HttpContext.Session.GetString("UserId"));
         BookMaster bookToAdd = new BookMaster
         {
             Title            = book.Title,
             Author           = book.Author,
             ShortDescription = book.ShortDescription,
             LongDescription  = book.LongDescription,
             UserId           = userId
         };
         if (_bookMasterRepository.AddBook(bookToAdd) > 0)
         {
             return(RedirectToAction("Index", "Book"));
         }
         ModelState.AddModelError("", "Operation unsuccessful. Book already present in database.");
         return(View(book));
     }
     return(View(book));
 }
コード例 #16
0
        public void DeleteBook(int bookID)
        {
            BookMaster book = _context.BookMasters.Find(bookID);

            _context.BookMasters.Remove(book);
        }
コード例 #17
0
 public async Task <BookMaster> AddBookMaster(BookMaster newBook)
 {
     return(await httpClient.PostJsonAsync <BookMaster>("api/BookMaster", newBook));
 }
コード例 #18
0
 public void InsertBook(BookMaster book)
 {
     _context.BookMasters.Add(book);
 }
コード例 #19
0
 public void UpdateBook(BookMaster book)
 {
     _context.Entry(book).State = EntityState.Modified;
 }
コード例 #20
0
 public ActionResult Edit(BookMaster bookmaster)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookmaster).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(bookmaster);
 }