Skip to content

Commit

Permalink
Updated Assigment V_0_14_810
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 remove try-catch.
=>Edit library, update methods to their unique work.
=>Make BasicTest, BookTest classes. and add methods on it. All work as expect.
  • Loading branch information
13014932 committed May 14, 2018
1 parent 877fcf9 commit a543fbe
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 80 deletions.
54 changes: 54 additions & 0 deletions app/Box.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace App;

class Box
{
/**
* @var array
*/
protected $items = [];

/**
* Construct the box with the given items.
*
* @param array $items
*/
public function __construct($items = [])
{
$this->items = $items;
}

/**
* Check if the specified item is in the box.
*
* @param string $item
* @return bool
*/
public function has($item)
{
return in_array($item, $this->items);
}

/**
* Remove an item from the box, or null if the box is empty.
*
* @return string
*/
public function takeOne()
{
return array_shift($this->items);
}

/**
* Retrieve all items from the box that start with the specified letter.
*
* @param string $letter
* @return array
*/
public function startsWith($letter)
{
return array_filter($this->items, function ($item) use ($letter) {
return stripos($item, $letter) === 0;
});
}
}
32 changes: 17 additions & 15 deletions app/Http/Controllers/Crud/BooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function storeNewBook(Request $request)
$data = new BookShopLib();
$data->storeNewBook($request);

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

} catch (\Exception $e) {
return back()->withErrors( 'OOPS.! Error In Creating New Book.');
Expand All @@ -65,20 +65,7 @@ public function storeNewBook(Request $request)

}

// method to DELETE BOOK.
public function bookdelete(Request $request)
{
try {
$delBook = new BookShopLib();
$delBook->bookdelete($request->book_del_id);

return back();

} catch (\Exception $e) {
return back()->withErrors( 'OOPS. Error In Book Delete..!');

}
}

//method to UPDATE Book Data.

Expand All @@ -98,7 +85,7 @@ public function bookUpdate(Request $request)
$bookUpdate = new BookShopLib();
$bookUpdate->bookUpdate($request);

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

} catch (\Exception $e) {
return back()->withErrors( 'OOPS.! Error In Book Update.');
Expand All @@ -108,6 +95,21 @@ public function bookUpdate(Request $request)

}

// method to DELETE BOOK.
public function bookdelete(Request $request)
{
try {
$delBook = new BookShopLib();
$delBook->bookdelete($request->book_del_id);

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

} catch (\Exception $e) {
return back()->withErrors( 'OOPS. Error In Book Delete..!');

}
}

// Method to display error on a page.
public function errors()
{
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Crud/BuyBooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public function storeBookAfterBuy(Request $request)
{
try {
$data = new BuyBookShopLib();
return $data->storeBookAfterBuy($request);
$data->storeBookAfterBuy($request);


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

}
catch (\Exception $e) {
Expand All @@ -34,7 +34,7 @@ public function storeBookAfterBuy(Request $request)
public function viewBooksAfterBuy()
{

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

return view('user.Buydbooks', ['buydbooks' => $data]);
Expand Down
65 changes: 25 additions & 40 deletions app/Lib/Crud/BookShopLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
class BookShopLib
{

// for testing PuposeOnly test -tests-
public static function sum($a,$b){

return $c=$a+$b;
}

//Method Retrun User Books.
public function getBooks(): array
{
Expand All @@ -29,7 +35,7 @@ public function getBooks(): array
// method to store NEW BOOK data
public function storeNewBook($data)
{
try {

$saveBooks = new Book;

$saveBooks->name = $data->book_name;
Expand All @@ -38,61 +44,34 @@ 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 back()->with('success', ['New Book Successfully Created.']);


} catch (\Exception $e) {
return back()->withErrors( 'OOPS.! Error In Creating New Book.');

return $saveBooks->save();

}
}

// method to DELETE Book.
public function bookdelete($id)
{
try {
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 back()->withErrors( 'OOPS.! Error In Book Delete.');


}
}

//method to UPDATE Book Data.
public function bookUpdate($data)
{
try {


$id = array("id" => $data->id);


$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);


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

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

} catch (\Exception $e) {
return back()->withErrors( 'OOPS.! Error In Book Update.');

}

}
// method to DELETE Book.
public function bookdelete($id)
{

return Book::destroy($id);
}

// method to get books to admin books view. (to datatable)
Expand All @@ -104,10 +83,16 @@ public function getAPIBooks()
}

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

return Book::find($id);
$book= Book::find($id);
$bookqty = $book->quantity;
// dd($bookqty);

$book->quantity = $bookqty - ($buyedBookQty);

return $book->save();

}

Expand Down
22 changes: 4 additions & 18 deletions app/Lib/Crud/BuyBookShopLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BuyBookShopLib
// Method to store BOOK AFTER BUY.
public function storeBookAfterBuy($data)
{
try {


$saveBook = new Buybook;

Expand All @@ -26,26 +26,12 @@ public function storeBookAfterBuy($data)

$saveBook->save();
// SUBTRACT the buying quantity from BOOKS table.

$buyedbook=$data->model_book_quantity;
$buyedBookQty=$data->model_book_quantity;
$book_id=$data->book_id;

$book = new BookShopLib();
$saveBook = $book->subtractBookQuantity($book_id);
$bookqty = $saveBook->quantity;
// dd($buydbook);

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

$saveBook->save();
$subBook = new BookShopLib();
$subBook->subtractBookQuantity($book_id,$buyedBookQty);

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

} catch (\Exception $e) {
return redirect('userbooks')->withErrors( 'OOPS.! Error In purchesing Book.');


}

}

Expand Down
24 changes: 24 additions & 0 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php echo View::make('layouts.app'); ?>


{{--<div class="container">--}}
{{--<div class="row justify-content-center">--}}
{{--<div class="col-md-8">--}}
{{--<div class="card">--}}
{{--<div class="card-header">Dashboard</div>--}}

{{--<div class="card-body">--}}
{{--if (session('status')){--}}
{{--<div class="alert alert-success">--}}
{{--{{ session('status') }}--}}
{{--</div>--}}
{{--}--}}

{{--You are logged in!--}}
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}


2 changes: 1 addition & 1 deletion resources/views/layouts/BootStrapTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ function myFunction(split) {
<input type="hidden" name="_token" value="<?php echo csrf_token() ?>"/>

<div class="modal-header">
<h4 class="modal-title">Delete Vendor ?</h4>
<h4 class="modal-title">Delete Book ?</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
</button>
</div>
Expand Down
Loading

0 comments on commit a543fbe

Please sign in to comment.