ASP.net core find model.primary_key_field_name in custom scaffolding - model-view-controller

I have an asp.net core MVC project I am creating custom scaffolding template files
I am following this answer to add custom scaffolding template pages
on Details page I want o add link to Listing, Edit and Delete page as below
#using System.Linq
##model #Model.ViewDataTypeName
#: <div class="card-body py-2">
#: <a asp-action="Delete" asp-route-id="##Model.pkName" class="float-right btn-floating btn-sm btn-danger m-0" title="Delete #Model.ViewDataTypeShortName Record"><i class="fa fa-trash"></i></a>
#: <a asp-action="Edit" asp-route-id="##Model.pkName" class="float-right btn-floating btn-sm btn-warning m-0 mr-2" title="Edit #Model.ViewDataTypeShortName Record"><i class="fa fa-edit"></i></a>
#: <a asp-action="Index" class="float-right btn-floating btn-sm btn-info m-0 mr-2" title="Back to #Model.ViewDataTypeShortName listing page"><i class="fa fa-arrow-left"></i></a>
#: <h4 class="mb-2 mb-sm-0 pt-1">#Model.ViewDataTypeShortName Details</h4>
#: </div>
Notice asp-route-id="##Model.pkName" in above example, Actualloy here I need to put primaryKey field name dynamically, ##Model.pkName is not a valid property but I just wanted to show something here.

Related

How to add number_format decimal in laravel in html view?

does anyone know how to add the decimal number_format here?, I don't use the blade from Laravel but I route the view directly to html... so if I add the number_format attribute, I'm confused ;(
<tr dir-paginate="income in incomes | filter:searchText | itemsPerPage:20" total-items="totalItems">
<td>{{income.incomeTitle}}</td>
<td>{{income_cat[income.incomeCategory]}}</td>
<td>Rp.{{income.incomeAmount}}</td>
<td>{{income.incomeDate}}</td>
<td>{{income.incomeNotes}}</td>
<td>
<a ng-show="income.incomeImage != ''" target="_blank" href="{{'index.php/incomes/download/'+income.id}}"><button type="button" class="btn btn-success btn-circle" title="{{phrase.Download}}" tooltip><i class="fa fa-cloud-download"></i></button></a>
<button ng-show="$root.can('Incomes.editIncome')" ng-click="edit(income.id)" type="button" class="btn btn-info btn-circle" title="{{phrase.Edit}}" tooltip><i class="fa fa-pencil"></i></button>
<button ng-show="$root.can('Incomes.delIncome')" ng-click="remove(income,$index)" type="button" class="btn btn-danger btn-circle" title="{{phrase.Remove}}" tooltip><i class="fa fa-trash-o"></i></button>
</td>
</tr>

Submit Button not getting correct route to add new data in Laravel

I am facing problem for Submit Button not getting correct route to add new data.
2 Blade file with 2 Submit Button which need to save 2 data to 2 different tables.
Problem facing - Data submitted in 1 table for both submit button....
addnewBuffalo.blade.php
<div class="box-header with-border" align="right">
<button type="submit" class="btn btn-success btn"><i class="fa fa-floppy-o"></i> <b>Add
Buffalo</b></button><a href="" class="btn btn-warning btn"><i class="fa fa-refresh">
</i> <b> Refresh</b></a>
</div>
addnewcow.blade.php
<div class="box-header with-border" align="right">
<button type="submit" class="btn btn-success btn"><i class="fa fa-floppy-o"></i> <b>Add
Cow</b></button><a href="" class="btn btn-warning btn"><i class="fa fa-refresh"></i> <b>
Refresh</b></a>
</div>
web.php
Route:: post('submit', 'App\Http\Controllers\addnewbuffaloController#addbuffaloData')
->name('submit');
Route:: post('submit', 'App\Http\Controllers\addnewcowController#addcowData')
->name('submit');
You need to create 2 separate Route Names. Having ->name('submit') for both won't work. And having the same path won't work
Route::post('submit=buffalo', 'App\Http\Controllers\addnewbuffaloController#addbuffaloData')
->name('submit-buffalo');
Route::post('submit-cow', 'App\Http\Controllers\addnewcowController#addcowData')
->name('submit-cow');
Or if the form is wrapped by one form tag then you can handle both submissions in the one Controller action
<button type="submit" name="buffalo-submission">Save Buffalo</button>
<button type="submit" name="cow-submission">Save Cow</button>
Then in the controller action code you could check
if ($request->has('buffalo-submission') {
Do buffalo code
} else if ($request->has('cow-submission')) {
do cow code
}

Bootstrap 3 modal not opening in one click

my bootstrap 3 modal does not open up in one click everytime, sometimes it does not open up, sometimes it opens up after 2-3 mouse clicks, rarely it opens up in one click.
Basically I have trying to create a modal that will ask whether the user wants to delete it, if yes then send a post request to remove the value from the given database with the provided id in url.
It is a table of courses, all of them having its own delete button, and the id used is of the form id="deleteModal{{ $subtopic->subtopic_id }}"
this is my delete button
<td class="col-1"><a class="btn btn-danger btn-sm"><i class="fas fa-trash" data-toggle="modal" data-target="#deleteModal{{ $subtopic->subtopic_id }}"></i></a></td>
this is my modal
<div class="modal fade" id="deleteModal{{ $subtopic->subtopic_id }}">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Delete Course ?</h4>
</div>
<div class="modal-body">
<div >
<h4>Are you sure!</h4>
<form action="{{ url('superadmin/allcourses/'.$course->course_id.'/'.$topics->topic_id.'/'.$subtopic->subtopic_id ) }}" method="post">
#csrf
{{ method_field('DELETE') }}
<div style="text-align: center;"><button class="btn btn-danger" type="submit"><i class="fas fa-check-double"></i>Yes</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
It should always open up in one click, please help me out I can't find any reason why it happens.
You need to change the html as below in the td.
<td class="col-1">
<a class="btn btn-danger btn-sm" data-toggle="modal" data-target="#deleteModal{{ $subtopic->subtopic_id }}">
<i class="fas fa-trash">
</i>
</a>
</td>
data-target does not work on <i></i>

Buttons BackPack Laravel

I need some help on the backpack, the buttons.
I have a list of products, and in the edit and delete buttons I have added two more to the nutrient of a product and its price. Using the backpack I do not know how to load the id of the product in question to put this additional information. How can I do it?
Image
Inside the button view you created you should be able to use $entry. Check out https://laravel-backpack.readme.io/docs/crud-buttons for more info.
Even though this event happened more than 1 month, I'll try to share some information to help others.
1. First of all you need to create a new blade file
resources\views\vendor\backpack\buttons\crud\buttons.
2. Inside of your file
<i class='fa fa-list'></i>Listar Nutrientes
The $entry->getKey() is going to provide the "id" to you.
3. Connecting the "Button" to your CrudCrontroller
Inside your ProductCrudController you need to add a new entry.
$this->crud->addButtonFromView('line', 'extra_button', 'extra_button', 'beginning');
the extra_button "just a example" needs to have the name of your blade file in the third parameter "if i'm not wrong".
After this you should get your new button for each line listed in the table.
Just a tip: If you're going to add "a lot of buttons" try to use a
drop down button.
<div class="btn-group">
<button type="submit" class="btn btn-primary btn btn-xs btn-default">
<span class="fa fa-list" role="presentation" aria-hidden="true" style="color: #f1f1f1"></span>
<span data-value="save_and_back" style="color: #fff">Opções</span>
</button>
<button type="button" class="btn btn-primary dropdown-toggle btn-xs btn-default" data-toggle="dropdown" aria-haspopup="true" aira-expanded="false" aria-expanded="true">
<span class="caret"></span>
<span class="sr-only">▼</span>
</button><div class="dropdown-backdrop"></div>
<ul class="dropdown-menu" style="font-size: 12px;">
<li><i class='fa fa-plus'></i>Add new nutriente</li>
<li><i class='fa fa-list'></i>Listar nutrientes</li>
<li><i class='fa fa-arrow-right'></i>Second Action</li>
<li><i class='fa fa-times'></i>Cancel</li>
</ul>
</div>

Robot Framework doesn't find element correctly by xpath

Robot framework doesn't identify the element by xpath.
Following is the code
<div id="sticky-actions-sticky-wrapper" class="sticky-wrapper" style="height: 100px;"><section class="content-header" id="sticky-actions" style="">
<h1>Curriculum</h1>
<div class="breadcrumb save-message hidden">
<label class="text-success">
<i class="flaticon flaticon-circle-check"></i>
Saved <span>a few seconds ago</span>
</label>
</div>
<div class="row p-t-15">
<div class="col-xs-12">
<button type="button" class="btn btn-primary add-task-btn" disabled="">Create New Task</button>
<div class="btn-group m-r-15">
<button type="button" class="btn btn-primary dropdown-toggle add-statement-btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="">
Create <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a tabindex="0" class="add-curriculum-btn">Curriculum</a></li>
<li><a tabindex="0" class="add-learning-area-btn hidden">Learning Area</a></li>
<li><a tabindex="0" class="add-topic-btn hidden">Topic</a></li>
<li><a tabindex="0" class="add-outcome-btn hidden">Outcome</a></li>
</ul>
</div>
<button type="button" class="btn btn-circle btn-xs blue link-statements-btn" disabled="" data-toggle="tooltip" data-placement="top" title="" data-original-title="Link selected statements">
<i class="fa fa-link"></i>
</button>
</div>
</div>
</section></div>
Xpath I used to for find "Create" button:
xpath=//*[#id="sticky-actions-sticky-wrapper"]/div[2]/div/div/button
xpath=//*[#id="sticky-actions"]/div[2]/div/div/button[.//text() = 'Create']
Robot Framework step:
click element xpath=//*[#id="sticky-actions-sticky-wrapper"]/div[2]/div/div/button
Error:-
ValueError: Element locator 'xpath=//*[#id="sticky-actions-sticky-wrapper"]/div[2]/div/div/button' did not match any elements.
According to your XML, there is a section element inside the first div which you didn't include in your XPath. It should work if you add it:
//*[#id="sticky-actions-sticky-wrapper"]/section/div[2]/div/div/button
or
//*[#id="sticky-actions"]/div[2]/section/div/div/button[.//text() = 'Create']

Resources