Esempio n. 1
0
 public IHttpActionResult GetAllbook()
 {
     try
     {
         var response = _BookService.GetAllBooks();
         var log      = string.Format("Response: {0}", SerializationServices.SerializeJson(response));
         LogHelper.Info(log);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         LogHelper.Debug(ex);
         return(InternalServerError(ex));
     }
 }
Esempio n. 2
0
        public IHttpActionResult Returnbook(List <BookedHistory> request)
        {
            MyContext db = new MyContext();

            if (ModelState.IsValid)
            {
                var log = string.Format("Request: {0}, Response: {1}", SerializationServices.SerializeJson(request), BadRequest());
                LogHelper.Info(log);
                return(BadRequest());
            }

            try
            {
                //add unselected book to bookedhistory and add the quantity of unselected book
                foreach (var req in request)
                {
                    _BookedhistoryService.UpdateBookedHistory(req);
                    var qty = db.Books.Where(x => x.ID == req.BookID).ToList().FirstOrDefault();
                    //var cuntr = db.BookedHistories.Where(x => x.ID == req.BookID && x.Status == false).Count();

                    int qtynum  = qty.Quantity;
                    var updBook = qtynum + 1;

                    Book nm = new Book();
                    {
                        nm.Author_Name    = qty.Author_Name;
                        nm.CategoryID     = qty.CategoryID;
                        nm.ID             = qty.ID;
                        nm.ISBN           = qty.ISBN;
                        nm.Price          = qty.Price;
                        nm.Quantity       = updBook;
                        nm.Publisher_Date = qty.Publisher_Date;
                        nm.Title          = qty.Title;
                    }


                    _BookService.UpdateBook(nm);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ex);
                return(InternalServerError(ex));
            }

            return(Ok("successfully Returned"));
        }
Esempio n. 3
0
 public IHttpActionResult GetAllbooked(string isbn, string title, bool status)
 {
     try
     {
         //var log = string.Format("Request: {0}", SerializationServices.SerializeJson(request));
         //LogHelper.Info(log);
         var response = _BookedhistoryService.GetAllBookHistory(isbn, title, status);
         var log      = string.Format("Response: {0}", SerializationServices.SerializeJson(response));
         LogHelper.Info(log);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         LogHelper.Debug(ex);
         return(InternalServerError(ex));
     }
 }
Esempio n. 4
0
 public IHttpActionResult Addbook([FromBody] Book request)
 {
     if (ModelState.IsValid)
     {
         var log = string.Format("Request: {0}, Response: {1}", SerializationServices.SerializeJson(request), BadRequest());
         LogHelper.Info(log);
         return(BadRequest());
     }
     try
     {
         var log = string.Format("Request: {0}", SerializationServices.SerializeJson(request));
         LogHelper.Info(log);
         var response = _BookService.SaveBook(request);
         log = string.Format("Response: {0}", SerializationServices.SerializeJson(response));
         LogHelper.Info(log);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         LogHelper.Debug(ex);
         return(InternalServerError(ex));
     }
 }
Esempio n. 5
0
        public IHttpActionResult booked(List <BookedHistory> request)
        {
            MyContext db = new MyContext();

            if (ModelState.IsValid)
            {
                var log = string.Format("Request: {0}, Response: {1}", SerializationServices.SerializeJson(request), BadRequest());
                LogHelper.Info(log);
                return(BadRequest());
            }
            try
            {
                //to check if the selected book still available
                var resutw = "No Available book for ID {0}";
                foreach (var reqw in request)
                {
                    var qty   = db.Books.Where(x => x.ID == reqw.BookID).ToList().FirstOrDefault();
                    var cuntr = db.BookedHistories.Where(x => x.ID == reqw.BookID && x.Status == true).Count();

                    int qtynum = qty.Quantity;
                    if (cuntr > qtynum)
                    {
                        return(Ok(resutw));
                    }
                }
            }
            catch (Exception x)
            {
                LogHelper.Debug(x);
                throw x;
            }

            try
            {
                //add selected book to bookedhistory and reduce the quantity of selected book
                foreach (var req in request)
                {
                    _BookedhistoryService.SaveBookedHistory(req);
                    var qty   = db.Books.Where(x => x.ID == req.BookID).ToList().FirstOrDefault();
                    var cuntr = db.BookedHistories.Where(x => x.ID == req.BookID && x.Status == true).Count();

                    int qtynum  = qty.Quantity;
                    var updBook = qtynum - cuntr;

                    Book nm = new Book();
                    {
                        nm.Author_Name    = qty.Author_Name;
                        nm.CategoryID     = qty.CategoryID;
                        nm.ID             = qty.ID;
                        nm.ISBN           = qty.ISBN;
                        nm.Price          = qty.Price;
                        nm.Quantity       = updBook;
                        nm.Publisher_Date = qty.Publisher_Date;
                        nm.Title          = qty.Title;
                    }


                    _BookService.UpdateBook(nm);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ex);
                return(InternalServerError(ex));
            }

            return(Ok("successfully added"));
        }