We have 1000 small lookup table editor in database. Each having few rows maximum. Instead of writing 1000 Apis, services, angular proxies we created an Object lookup viewer/editor in grid cell. Small Tables like ProductCodeLookup, AddressType, SupplyCategory, FurnitureType
Also there is API Operator from a webpage, where people can See and Add Rows to the lookup Tables. (see picture link below)
The question came up, how do we dynamically apply Model Validation on the Request Object in API?
Front end validation is on Angular
However, for C#, we want all LookupIds and int category to be 1-100 max. String request members to be 255 characters max. Emails to be in #email regex format etc. We may not know what Object request looks like at runtime, until table is selected.
[HttpPost("[Action]")]
public void AddObject(List<object> addListRequest, string lookupTableName)
{
foreach (var addItem in addListRequest)
{
var addItemCast = addItem.ConvertObjectToTypeWithSerialization(atype);
context.Add(addItemCast);
}
}
This answer for older Net MVC, we are using Net Core 3 API. Dynamically apply validation rules at runtime with ASP.NET MVC 4
Thought there is method to conduct this with new library.
EditorImage
Related
Pulling in data from an API and populating my database with said data. All fields in database are populating as they should, except the ID field which is auto incrementing. Need to turn this off as I am relying on the ID from the API to operate most of my site.
Google around and tried using this
[System.ComponentModel.DataAnnotations.KeyAttribute()]
didnt do anything though....
This is how i am recieving my data from the API call, all checks out:
[{"id":"40387124","name":"Abyss Flower","type":"Normal Monster","desc":"A rarely seen flower that blossoms quietly on the edge of darkness.","atk":"750","def":"400","level":"2","race":"Plant","attribute":"EARTH","card_images":[{"id":"40387124","image_url":"https://storage.googleapis.com/ygoprodeck.com/pics/40387124.jpg","image_url_small":"https://storage.googleapis.com/ygoprodeck.com/pics_small/40387124.jpg"}],"card_prices":{"cardmarket_price":"0.00","tcgplayer_price":"0.00","ebay_price":"10.99","amazon_price":"0.00"}}]
however, my table is populating like so:
19 Abyss Flower 750 400 A rarely seen flower that blossoms quietly on the edge of darkness. 2 Normal Monster EARTH
instead of 19, which is the auto incremented ID generate from the database, I need to be able to accept the ID from the API, 40387124
You can use the Key attribute with the database generated option:
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
or if you are using fluentAPI then like so:
modelBuilder.Entity<MyEntity>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
So i just recently able to play with google spreadsheet API,
i intend to use it as my C# apps database, so people can use either web (via docs) or desktop (via C#).
There are 1 problem that i'm afraid of: Will there conflict if 2 people are doing inserting + updating.
Scenario:
There are 2 user,
A will be in charge of adding new row
B will be in charge of reviewing A work and putting comment.
Both A and B will working at the same time.
Conflict I'm afraid of:
When B using the apps to update comment, the apps will get the data and have the row ranges, let say A100:H100, Then A proceed to add data.
I'm afraid that if the data is added above A100:H00, then when the apps submit changes from B, it will not placed in correct row.
Is there anyway to avoid this?
Yes, you can Add and update at the same time by using Google Sheets API. batchUpdate would be the best method to work by taking one or more request objects, each one specifying a single kind of request to perform.
When updating a spreadsheet, some kinds of requests may return responses. These are returned in an array, with each response occupying the same index as the corresponding request. Some requests do not have responses. For those requests, the response will be empty.
Typically the "Add" requests will have responses, so that you know information (such as the ID) of the newly added object. See Response for the list of supported responses.
Sample update from response:
{
// Union field kind can be only one of the following:
"addNamedRange": {
object(AddNamedRangeResponse)
},
"addSheet": {
object(AddSheetResponse)
},
"addFilterView": {
object(AddFilterViewResponse)
},
I have an index page where a table is generated with rows of information from the DB.
I have successfully integrated Tom Dykstra's method of adding a search box using this tutorial: http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
How would I implement behavior that shows names that already exist as they are being typed in the search box, or automatically update the rows in the table as something is typed into the search box?
I am using MVC 5 with EF6.
Thank you!
I would use the jQuery UI Autocomplete widget with a remote source for the data.
https://jqueryui.com/autocomplete/#remote
For the remote source either write a new action on your controller that returns JSON, or a WebAPI action to do the same, and in there do a query against your database to find matching results for the users query
The best way to do this would be to use AngularJs. We can't give you a full example of this, I can only give you an approach. Angular is very powerful and as well it is client side which speeds up you application very much. See the example shown in the docs of angular.
You can use the filtering on everything (tables, divs, list etc.)
https://docs.angularjs.org/api/ng/filter/filter
Here is an example of how to implement AngularJS in Asp.Net MVC.
http://www.codeproject.com/Articles/806029/Getting-started-with-AngularJS-and-ASP-NET-MVC-Par
Here is also an JSFiddle example on how it can look like:
http://jsfiddle.net/mikeeconroy/QL28C/1/
<tr ng-repeat="product in products | filter:search | orderBy:'name'">
<td>{{product.name}}</td>
<td>{{product.category}}</td>
</tr>
This code snippet would do the filtering for you
I have a conceptual problem.
For an ASP.NET MVC / C# website (although the exact technology may not be that important) I have 2 linked drop downs (html select) with Countries and Cities of a continent.
These are currently kept in 2 database tables and as you imagine the Cities table has round 10 000 records.
The current functionality is:
- initially the country select is populated.
- the user selects a country, an ajax request goes to the server, retrieves the cities for that country_id and populates the second (cities) select.
Sometimes it gets a bit slow as you might imagine, and since these are in the end static values (the lists will not change) what will be the best way to treat this situation?
I would recommend implementing it, using the jquery chosen plugin Chosen
plugin that can be used to filter, results, but since you are getting such a big response you can incorporate a search filter functionality with ajax as shown here, Jquery Ajax-Chosen
So, I'm facing a problem here. I'm building an ASP.NET MVC application, and the final stage is to implement a search page feature that uses multiple filters to perform the search.
I've done a model class called SearchModel that has some properties, among em' is a collection of search filters. The problem is at the search results page. I need to preserve the whole SearchModel as search criteria and additional paging parameters. I'd like to add links to next and previous pages and stuff like that, only available by a GET request. If I enable GET I get a HUGE query string containing the whole model as follows:
Documents/Search?CriteriaFilters[0].Field=OwnerUserName&CriteriaFilters[0].Type=Text&CriteriaFilters[0].Text=albert.sheppard&CriteriaFilters[0].TextMatchMode=Exactly
And that's only using one filter with a small criteria text. Looks bad and nasty when I'm using 10+ filters.
How you pro's handle search and results pages with multiple filters without parsing the whole model to the query string? Query string encryption? If so, how to achieve this?
Thanks.
I don't know about ASP.NET MVC, but it should be done with POST. I understand many of your fields are unused in your example, but they might as well have values, and the size of GET is very limited. Or maybe you can come up with a very compressed way of representing your criteria. But still, POST is a lot better.
I have implemented search criteria URL using MVC as follows:
acer notebook >> Notebook >> 15.6in >> Core 2 Duo
http://myserver/SearchApp/Search/4/acer%20notebook/1/50-97-77868%2c50-111-76631?sort=0&catGrp=50
private
ActionResult SearchAction
(
int siteId,
string query,
int? page,
string options,
SortType sortType,
int catGroupId
)
{
// Search code implementation
}
The above URL and controller translation is as follows:
Search - Action
4 - siteId
acer%20notebook - query
50-97-77868%2c50-111-76631 - options (it is a comma separated list of options), which represents 15.6in >> Core 2 Duo
0 - sortType
50 - catGroup
Hope this will help.