Skip to content

Commit

Permalink
Updated Assigment V_0_12_610
Browse files Browse the repository at this point in the history
I update.

=>Edit controllers update methods.
apply try-catch with proper notification.
=>Edit libraries update methods apply try-catch with proper notification.
  • Loading branch information
13014932 committed May 12, 2018
1 parent ccff441 commit 877fcf9
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 93 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Crud/BooksAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getBooks()

}
catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
log::error($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());


}
Expand Down
29 changes: 13 additions & 16 deletions app/Http/Controllers/Crud/BooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;


class BooksController extends Controller
{
Expand All @@ -29,7 +29,7 @@ public function userbooks()
return view('user.userbooks', ['showdata' => $Books]);

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return redirect('errors')->withErrors( 'OOPS.! Error In Loading... Books.');


}
Expand All @@ -46,7 +46,7 @@ public function storeNewBook(Request $request)

]);
if ($validator->fails()) {
return redirect('errors')
return back()
->withErrors($validator)
->withInput();
}
Expand All @@ -56,10 +56,10 @@ public function storeNewBook(Request $request)
$data = new BookShopLib();
$data->storeNewBook($request);

return redirect('/adminbooks');
return back();

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return back()->withErrors( 'OOPS.! Error In Creating New Book.');

}

Expand All @@ -72,10 +72,10 @@ public function bookdelete(Request $request)
$delBook = new BookShopLib();
$delBook->bookdelete($request->book_del_id);

return redirect('/adminbooks');
return back();

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return back()->withErrors( 'OOPS. Error In Book Delete..!');

}
}
Expand All @@ -90,33 +90,30 @@ public function bookUpdate(Request $request)

]);
if ($validator->fails()) {
return redirect('errors')
return back()
->withErrors($validator)
->withInput();
}
try {
$bookUpdate = new BookShopLib();
$bookUpdate->bookUpdate($request);

return redirect('/adminbooks');
return back();

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return back()->withErrors( 'OOPS.! Error In Book Update.');


}

}

// Method to display error on a page.
public function errors()
{
try {
return view('post.errors');
return view('post.errors');
}

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());


}
}
}
17 changes: 5 additions & 12 deletions app/Http/Controllers/Crud/BuyBooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public function storeBookAfterBuy(Request $request)
{
try {
$data = new BuyBookShopLib();
$data->storeBookAfterBuy($request);
return $data->storeBookAfterBuy($request);


return redirect('buydbooks');
// return redirect('buydbooks')->with('success', ['New Book Successfully Createsdasdasdad.']);

}
catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return redirect('userbooks')->withErrors( 'OOPS.! Error In purchesing Book.');


}
Expand All @@ -34,17 +34,10 @@ public function storeBookAfterBuy(Request $request)
public function viewBooksAfterBuy()
{

try {
$data = new BuyBookShopLib();
$data = new BuyBookShopLib();
$data = $data->viewBooksAfterBuy();

return view('user.Buydbooks', ['buydbooks' => $data]);

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());


}
return view('user.Buydbooks', ['buydbooks' => $data]);


}
Expand Down
61 changes: 19 additions & 42 deletions app/Lib/Crud/BookShopLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public function storeNewBook($data)
$saveBooks->special_price = $data->special_price;
$saveBooks->book_created_date = $data->book_created_date;
$saveBooks->quantity = $data->quantity;
$saveBooks->save();

return $saveBooks->save();
return back()->with('success', ['New Book Successfully Created.']);


} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return back()->withErrors( 'OOPS.! Error In Creating New Book.');


}
Expand All @@ -53,12 +54,19 @@ public function storeNewBook($data)
public function bookdelete($id)
{
try {
$delBook = Book::destroy($id);

return $delBook;
Book::destroy($id);
// if (!empty($bookdel))
// {-
// return back()->with('success', ['Book Successfully Deleted']);
//
// }
// else{
// return back()->withErrors( 'OOPS.! Error In Book Deletefirst.');
// }
return back()->with('success', ['Book Successfully Deleted.']);

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return back()->withErrors( 'OOPS.! Error In Book Delete.');


}
Expand All @@ -75,26 +83,13 @@ public function bookUpdate($data)
$bookUpdates = array("name" => $data->name, "price" => $data->price, "author_name" => $data->author_name,
"special_price" => $data->special_price, "book_created_date" => $data->book_created_date, "quantity" => $data->quantity);

$result = Book::updateOrCreate($id, $bookUpdates);

if (!$result) {
throw new Exception("Error in book updateOrCreate");
}

// $bookUpdate= Book::find($data->update_book_id);
//
// $bookUpdate->name = $data->update_book_name;
// $bookUpdate->price = $data->update_book_price;
// $bookUpdate->author_name = $data->update_book_author_name;
// $bookUpdate->special_price = $data->update_book_special_price;
// $bookUpdate->book_created_date = $data->update_book_created_date;
// $bookUpdate->quantity = $data->update_book_quantity;
//
// return $bookUpdate->save();
Book::updateOrCreate($id, $bookUpdates);

return back()->with('success', ['Book Successfully Updated.']);

} catch (\Exception $e) {
Log::error($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return back()->withErrors( 'OOPS.! Error In Book Update.');


}
Expand All @@ -103,35 +98,17 @@ public function bookUpdate($data)
// method to get books to admin books view. (to datatable)
public function getAPIBooks()
{
try {
$getbooks = Book::select('id', 'name', 'price', 'special_price', 'author_name', 'book_created_date', 'quantity');

return $getbooks;

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());

return Book::select('id', 'name', 'price', 'special_price', 'author_name', 'book_created_date', 'quantity');

}
}

// method SUBTRACT the buying quantity from BOOKS table.
public function subtractBookQuantity($id)
{
try {

$saveBook = Book::find($id);

return $saveBook;

// return Book::updateOrCreate(['quantity' => '$qty'],['id' => '$id']);

return Book::find($id);

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());


}
}


Expand Down
5 changes: 3 additions & 2 deletions app/Lib/Crud/BuyBookShopLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public function storeBookAfterBuy($data)

$saveBook->quantity = $bookqty - ($buyedbook);

return $saveBook->save();
$saveBook->save();

return redirect('buydbooks')->with('success', ['Book purchesed Successfully.']);

} catch (\Exception $e) {
return ($e->getMessage() . " => on file " . $e->getFile() . " => on line number = " . $e->getLine());
return redirect('userbooks')->withErrors( 'OOPS.! Error In purchesing Book.');


}
Expand Down
34 changes: 34 additions & 0 deletions resources/views/admin/adminbooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@
<?php echo View::make('layouts.BootStrapTable'); ?>
<?php echo View::make('datatable.DataTableLib'); ?>

<h1></h1>
<?php

if (Session::has('success')) {

echo "<div class=\"alert alert-success\" > <ul >" ;

foreach (Session::get('success') as $suc) {


echo "<h2 ><li >".$suc."</li ></h2 ></ul>
</div>";


}

}

if ($errors->any()) {

echo "<div class=\"alert alert-danger\" > <ul >" ;

foreach ($errors->all() as $error) {


echo "<h2 ><li >".$error."</li ></h2 >";


}

}
?>
</ul>
</div>

<div class="container">
<div class="table-wrapper">
Expand Down
19 changes: 10 additions & 9 deletions resources/views/layouts/BootStrapTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,31 +493,32 @@ function myFunction(split) {
<div class="modal-body">
<div class="form-group">
<label>book_id</label>
<input type="text" name="update_book_id" id="update_book_id" class="form-control" readonly>
<input type="text" name="id" id="update_book_id" class="form-control" readonly>
</div>
<div class="form-group">
<label>book_name</label>
<input type="text" name="update_book_name" id="update_book_name" class="form-control">
<input type="text" name="name" id="update_book_name" class="form-control">
</div>
<div class="form-group">
<label>price</label>
<input type="number" name="update_book_price" id="update_book_price" class="form-control">
<input type="number" name="price" id="update_book_price" class="form-control">
</div>
<div class="form-group">
<label>author_name</label>
<input type="text" name="update_book_author_name" id="update_book_author_name" class="form-control">
<label>special_price</label>
<input type="number" name="special_price" id="update_book_special_price" class="form-control">
</div>
<div class="form-group">
<label>special_price</label>
<input type="number" name="update_book_special_price" id="update_book_special_price" class="form-control">
<label>author_name</label>
<input type="text" name="author_name" id="update_book_author_name" class="form-control">
</div>

<div class="form-group">
<label>book_created_date</label>
<input type="text" name="update_book_created_date" id="update_book_created_date" class="form-control">
<input type="date" data-date-inline-picker="true" name="book_created_date" id="update_book_created_date" class="form-control">
</div>
<div class="form-group">
<label>quantity</label>
<input type="number" name="update_book_quantity" id="update_book_quantity" class="form-control">
<input type="number" name="quantity" id="update_book_quantity" class="form-control">
</div>
</div>
<div class="modal-footer">
Expand Down
11 changes: 0 additions & 11 deletions resources/views/post/errors.blade.php

This file was deleted.

20 changes: 20 additions & 0 deletions resources/views/post/errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1></h1>
<?php
if ($errors->any()) {

echo "<div class=\"alert alert-danger\" > <ul >" ;

foreach ($errors->all() as $error) {


echo "<h2 ><li >".$error."</li ></h2 >";


}

}
?>
</ul>
</div>


Loading

0 comments on commit 877fcf9

Please sign in to comment.