Ejemplo n.º 1
0
 /// <summary>
 /// This method  is created for getting all books details.
 /// </summary>
 /// <returns></returns>
 public List <BooksDetail> GetAllBooksDetails()
 {
     try
     {
         List <BooksDetail> bookstorelist = new List <BooksDetail>();
         using (SqlConnection connection = new SqlConnection(configuration.GetConnectionString("UserDbConnection")))
         {
             SqlCommand command = new SqlCommand("spGetAllBookDetails", connection);
             command.CommandType = CommandType.StoredProcedure;
             connection.Open();
             SqlDataReader sqlreader = command.ExecuteReader();
             while (sqlreader.Read())
             {
                 BooksDetail book = new BooksDetail();
                 book.BookId     = Convert.ToInt32(sqlreader["BookId"]);
                 book.BookName   = sqlreader["BookName"].ToString();
                 book.AuthorName = sqlreader["AuthorName"].ToString();
                 book.Price      = Convert.ToDouble(sqlreader["Price"]);
                 book.Quantity   = Convert.ToInt32(sqlreader["Quantity"]);
                 book.Catagory   = sqlreader["Catagory"].ToString();
                 book.BookImage  = sqlreader["BookImage"].ToString();
                 book.Rating     = Convert.ToDouble(sqlreader["Rating"]);
                 bookstorelist.Add(book);
             }
             connection.Close();
         }
         return(bookstorelist);
     }
     catch (CustomException exception)
     {
         throw new CustomException(CustomException.ExceptionType.NULL_EXCEPTION, exception.Message);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is created for adding book details.
        /// </summary>
        /// <param name="booksDetail"></param>
        /// <returns></returns>
        public object AddBookDetails(BooksDetail booksDetail)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(configuration.GetConnectionString("UserDbConnection")))
                {
                    SqlCommand cmd = new SqlCommand("spAddBooksDetail", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    // cmd.Parameters.AddWithValue("@BookId", booksDetail.BookId);
                    cmd.Parameters.AddWithValue("@BookName", booksDetail.BookName);
                    cmd.Parameters.AddWithValue("@AuthorName", booksDetail.AuthorName);
                    cmd.Parameters.AddWithValue("@Price", booksDetail.Price);
                    cmd.Parameters.AddWithValue("@Quantity", booksDetail.Quantity);
                    cmd.Parameters.AddWithValue("@Catagory", booksDetail.Catagory);
                    cmd.Parameters.AddWithValue("@BookImage", booksDetail.BookImage);
                    cmd.Parameters.AddWithValue("@Rating", booksDetail.Rating);

                    con.Open();
                    int i = cmd.ExecuteNonQuery();
                    con.Close();
                    return(true);
                }
            }
            catch (CustomException exception)
            {
                throw new CustomException(CustomException.ExceptionType.NULL_EXCEPTION, exception.Message);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("BookID,BookName,Author,Publisher,BookDescription,Extension,CategoryID")] BooksDetail booksDetail)
        {
            if (id != booksDetail.BookID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(booksDetail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BooksDetailExists(booksDetail.BookID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(booksDetail));
        }
Ejemplo n.º 4
0
        public IActionResult AddBookDetails(BooksDetail booksDetail)
        {
            string message;
            var    result = this.manager.AddBookDetails(booksDetail);

            try
            {
                if (!result.Equals(null))
                {
                    message = "Book details added successfully.";
                    msmq.SendMessage("Books name " + booksDetail.BookName + " added successfully.", result);
                    this._distributedCache.Remove(key);
                    return(this.Ok(new { message, result }));
                }
                message = "Please insert correct book details.!!";
                return(BadRequest(new { message }));
            }
            catch (CustomException)
            {
                return(BadRequest(CustomException.ExceptionType.INVALID_INPUT));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("BookID,BookName,Author,Publisher,BookDescription,File,CategoryID")] BooksDetail booksDetail)
        {
            using (var memoryStream = new MemoryStream())
            {
                await booksDetail.File.FormFile.CopyToAsync(memoryStream);

                string photoname = booksDetail.File.FormFile.FileName;
                booksDetail.Extension = Path.GetExtension(photoname);
                if (!".pdf".Contains(booksDetail.Extension.ToLower()))
                {
                    ModelState.AddModelError("File.FormFile", "Only PDF Format is Allowed.");
                }
                else
                {
                    ModelState.Remove("Extension");
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(booksDetail);
                await _context.SaveChangesAsync();

                var uploadsRootFolder = Path.Combine(_environment.WebRootPath, "bookpdfs");
                if (!Directory.Exists(uploadsRootFolder))
                {
                    Directory.CreateDirectory(uploadsRootFolder);
                }
                string filename = booksDetail.BookID + booksDetail.Extension;
                var    filePath = Path.Combine(uploadsRootFolder, filename);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await booksDetail.File.FormFile.CopyToAsync(fileStream).ConfigureAwait(false);
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(booksDetail));
        }
Ejemplo n.º 6
0
 public object AddBookDetails(BooksDetail booksDetail)
 {
     return(this.detailsRepository.AddBookDetails(booksDetail));
 }