1

Topic: ASP.Net MVC 5 - at

At first I will describe a context. To whom mnoga-bukf, it is possible to pass at once to a question in the end of a post. As all happens: There was a functional on data input. The data was stored (and is stored till now) in the several tables connected or 1-0. 1, or 1-0. *, differently. In this connection originally all has been implemented so that in the beginning is entered the main record, we save it in a DB, then we enter dependent records and is saved also separately referring to the main record. For an example let's take essence of the user with several addresses. At first entered the user, then we enter its addresses. Users started to grumble that it is not joined to their sensation of business - they want to enter and save at once all at one stroke. Thus the all entered essence voluminous enough and on its input can decently leave time (for which can happen anything you like) and automatically there was a question that in the course of input it is necessary to do temporal savings that if something happens it was possible to return to earlier created object. As it was necessary to do quickly enough, decided to manage a temporariness flag in the main tables. I.e. now the essence is interposed into a DB at once in the beginning creations and all dependent objects can refer at once to it. In the end of editing (at pushing on final to "Save"), the temporariness flag is removed also essence becomes high-grade. From a negative: It was necessary to remove all compulsion of fields in a DB and from attributes of entities Entity Framework as temporal entities can be as much as incomplete. Upon server  even it is not done (left only client), but it is not accepted to speak about it in public. In any requests it was necessary  check of that temporal entities were not picked up. The code of saving of essence became difficult enough (if temporal saving, so and if is not present, ). That I want to make: to Create separate essence (that final all to tangle) for transient objects - on structure, strongly reduced model of the present objects. All operations will happen to temporal entities in the world, and while translating in constant tables all checks (i.e. again I will return compulsion of fields in a DB and in model EF) will be fulfilled. Where I see forthcoming complexities: . The matter is that the temporal model should not contain any attributes Required, etc. But  and I twist will operate first of all with temporal model. While translating temporal model in a constant I can involve checks, but all this automatic asp.net mvc   by default in ModelState will write titles of properties of constant model. Also I twist (working with temporal model) will not tint appropriate fields. Those who on a constant basis divides ViewModel and DomainModel possibly should face a similar problem. Wanted to learn, whether there are any operating time in connecting these layers not only from View to Domain, but also is reverse? I.e. that  the information from Domain' was normally applied in a presentation layer. A question briefly: If you divide ViewModel and DomainModel as thus View receives and displays errors  on Domain-model fields? Now I look AutoMapper, but something as though is not able it of it...

2

Re: ASP.Net MVC 5 - at

Hello, Neco, you wrote: N> That I want to make: N> to Create separate essence (that final all to tangle) for transient objects - on structure, strongly reduced model of the present objects. And it is necessary to do. These objects - model for users who carry out data input. As it it is convenient, so these objects and should accept the data. N> all operations will happen to temporal entities in the world, and while translating in constant tables all checks (i.e. again I will return compulsion of fields in a DB and in model EF) will be fulfilled. Checks should be fulfilled earlier - right after data input. Then application will trust this data on 100 % because the garbage did not transit the filter. N> where I see forthcoming complexities: N> Validatsija. The matter is that the temporal model should not contain any attributes Required, etc. But  and I twist will operate first of all with temporal model. While translating temporal model in a constant I can involve checks, but all this automatic asp.net mvc   by default in ModelState will write titles of properties of constant model. Also I twist (working with temporal model) will not tint appropriate fields. Exactly. If at once it is visible  this approach, what for on it to waste time? The user data structures should contain necessary  - then if the data transited , application can work with these structures further. N> those who on a constant basis divides ViewModel and DomainModel possibly should face a similar problem. Wanted to learn, whether there are any operating time in connecting these layers not only from View to Domain, but also is reverse? I.e. that  the information from Domain' was normally applied in a presentation layer. Look above. Application should trust to itself and not contain the garbage logic continually. Checks on a correctness and safety - care of other layers, exterior in relation to an application kernel. N> a question briefly: N> If you divide ViewModel and DomainModel as thus View receives and displays errors  on Domain-model fields? ViewModel it is rejected until from it it is impossible to receive correct DomainModel.

3

Re: ASP.Net MVC 5 - at

AutoMapper it is not necessary in  Domain <-> ViewModel It is possible to do modal dialogues on JS directly on page, and to save JSON in hidden field through JSON.stringify Decoder JSON for ViewModel: using System; using System. ComponentModel; using System. Linq; using System. Web. Mvc; using Newtonsoft. Json; namespace MyProject {public class JsonPropBinder: DefaultModelBinder {protected override object GetPropertyValue (ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder) {if (propertyDescriptor.Attributes.OfType<Attribute> ().Any (x => (x is JsonBindableAttribute))) {var value = bindingContext. ValueProvider. GetValue (bindingContext. ModelName).AttemptedValue; var settings = new JsonSerializerSettings {DateTimeZoneHandling = DateTimeZoneHandling. Unspecified}; return JsonConvert. DeserializeObject (value, propertyDescriptor. PropertyType, settings);} return base. GetPropertyValue (controllerContext, bindingContext, propertyDescriptor, propertyBinder);}}} Attribute for JSON fields ViewModel public class JsonBindableAttribute: Attribute {} Then you fasten FluentValidation to ViewModel where you check everything that generally it is possible to check up. In viewModel it is possible  the necessary data to  by means of the Binder then in FluentValidation it is possible to check up generally all. : on JS+JQuery in creation of difficult forms far you will not leave.

4

Re: ASP.Net MVC 5 - at

Hello, Vladek, you wrote: N>> That I want to make: N>> to Create separate essence (that final all to tangle) for transient objects - on structure, strongly reduced model of the present objects. V> and it is necessary to do. These objects - model for users who carry out data input. As it it is convenient, so these objects and should accept the data. Ok N>> all operations will happen to temporal entities in the world, and while translating in constant tables all checks (i.e. again I will return compulsion of fields in a DB and in model EF) will be fulfilled. V> Checks should be fulfilled earlier - right after data input. Then application will trust this data on 100 % because the garbage did not transit the filter. ... The Question where begins that application. If checks to do ViewModel' two complexities turn out: 1. Checks should be disconnected as I ViewModel will be simultaneously model of temporal essence which will be stored in a DB. While I see that EF at saving by the automatic machine runs check of attributes (it can is possible and to lower check in EF, I did not search while). 2. As we wholly trust layer ViewModel', in domain model of check it is already necessary not to do (to avoid duplication). But the matter is that there are also other methods of creation of entities - the automatic machine, without UI. Such entities it turns out will bypass check, or it will be necessary to do so that they too used ViewModel' that already it seems superfluous frauds. My experience prompts that checks () on the contrary should be fulfilled as it is possible more close to storage (in an ideal in a DB). Focus in that them to drag to the user and to show as soon as possible is should dare meta data. But the boundary should be or in a DB, or hardly earlier. N>> those who on a constant basis divides ViewModel and DomainModel possibly should face a similar problem. Wanted to learn, whether there are any operating time in connecting these layers not only from View to Domain, but also is reverse? I.e. that  the information from Domain' was normally applied in a presentation layer. V> look above. Application should trust to itself and not contain the garbage logic continually. Checks on a correctness and safety - care of other layers, exterior in relation to an application kernel. If to speak about layers generally their three, in this case we consider two - presentation and business logics. The correctness of entities in duplication avoidance should be checked in a business logic layer, and ViewModel this in itself the presentation counter - as can suit that fact, what the business logic is checked exceptional in a presentation layer? N>> If you divide ViewModel and DomainModel as thus View receives and displays errors  on Domain-model fields? V> ViewModel it is rejected until from it it is impossible to receive correct DomainModel. Here it agree - but a question in the mechanic. As I it see: ViewModel it is converted in DomainModel, DomainModel it is checked on a correctness, errors are translated in terms ViewModel'. As I understand that you describe: ViewModel it is checked on a correctness, it is then converted in DomainModel and it without the subsequent checks is saved in a DB. But it even generally is impossible - in ViewModel' there can be even not enough data for high-grade . I ask to explain thought.

5

Re: ASP.Net MVC 5 - at

Hello, B7_Ruslan, you wrote: B_R> AutoMapper it is not necessary in  Domain <-> ViewModel B_R> It is possible to do modal dialogues on JS directly on page, and to save JSON in hidden field through JSON.stringify B_R> In viewModel it is possible  the necessary data to  by means of the Binder then in FluentValidation it is possible to check up generally all. Some times read a post, but and did not understand at what here JS, JSON and jQuery. The question was entirely about a server part - that arrives in the controler and that is saved in a DB (and that thus  and as the error is displayed to the user). FluentValidation it is not used, but I do not see as it can help, if models two and have to be solved as well as where to do checks.

6

Re: ASP.Net MVC 5 - at

Hello, Neco, you wrote: N> the Question where begins that application. N> if checks to do ViewModel' two complexities turn out: N> 1. Checks should be disconnected as I ViewModel will be simultaneously model of temporal essence which will be stored in a DB. While I see that EF at saving by the automatic machine runs check of attributes (it can is possible and to lower check in EF, I did not search while). These structures model not objects of data domain, and input of the user. The user enters something into application - here we receive its input in the form of these data structures. From the user we should check input always and generally treat it with distrust. If them not to drag in an application kernel, and to use on an input, and then to throw out - to work with them easier. N> 2. As we wholly trust layer ViewModel', in domain model of check it is already necessary not to do (to avoid duplication). But the matter is that there are also other methods of creation of entities - the automatic machine, without UI. Such entities it turns out will bypass check, or it will be necessary to do so that they too used ViewModel' that already it seems superfluous frauds. Entities from data domain are created in an application kernel when input from the user is already received and checked up. How at this stage they can be incorrect? Application creates them according to the internal rules. A simple example: input from the user - file name, application model - the document from this file. From the user the file name is received only, with checks "the file exists" and "the format is supported", the document is loaded in application - the object of the document forms by application on the basis of the data from a file. Here already there will be checks of other sort - a correctness of the contained document, presence of all necessary sections for example - here it is business logic, and "the format is supported" - the exterior filter. N> My experience prompts that checks () on the contrary should be fulfilled as it is possible more close to storage (in an ideal in a DB). Focus in that them to drag to the user and to show as soon as possible is should dare meta data. But the boundary should be or in a DB, or hardly earlier. It is a little philosophy. Checks are on an input and on an output of a kernel of application ("business logic"). An input at it - input from the user. An output? Well, probably, that DB. And on the contrary, by the way. The application kernel should be able to obtain on an input the data from the user and from a DB, on an output to produce the data and to the user, and a DB. How many clusters of objects will be used here? I offer three, you want to manage one. Any methods are admissible, all depends on the task. Here these clusters of objects: the Data for the user, objects with names like Request/Response. Objects of business logic. Application do a certain operation, instead of it should is simple to throw at once the data in a DB - these objects it and are engaged. Objects of a DB. The kernel should save somewhere the state, it stuffs the data on these objects. These are objects for EF. Attention - they exterior in relation to an application kernel! A cluster No1 and No3 are simple data structures with necessary . On a basis  or still that. Whether the user specified this line, whether this column with the DB table is filled here. It does not concern business logic, these are input-output checks. The user is an input-output, the DB is too input-output. The cluster No2 answers a question - and that actually application does. Sometimes application does nothing! It takes any data from the user and adds them in a DB, takes the data from a DB and shows to their user. All. In this case in application there is no business logic and it is a normal situation for many applications which we saw on operation. Well, let us assume, we decided to manage generally one cluster of objects - we start to suffer at once inconveniences! At us the same object can be filled now by the person, and ORM-library! It turns out clearly and consistently in the most simple cases. This case show in the code in any books and articles - project any anemic blog where the same objects Post fly between the user and a DB. N> if to speak about layers generally their three, in this case we consider two - presentation and business logics. The correctness of entities in duplication avoidance should be checked in a business logic layer, and ViewModel this in itself the presentation counter - as can suit that fact, what the business logic is checked exceptional in a presentation layer? As I wrote above, in this case any business logic, probably, was not present - the task it is necessary to save user data in a DB and on the contrary - to give to their user. Yes, then it is enough two layers. Representation and storage. And in both layers there will be separate , after all an assignment at them a miscellaneous. N> here it agree - but a question in the mechanic. As I it see: ViewModel it is converted in DomainModel, DomainModel it is checked on a correctness, errors are translated in terms ViewModel'. N> As I understand that you describe: ViewModel it is checked on a correctness, it is then converted in DomainModel and it without the subsequent checks is saved in a DB. N> but it even generally is impossible - in ViewModel' there can be even not enough data for high-grade . N> I Ask to explain thought. Well the user fills any huge form, we on the basis of this form create and  object or a tree of objects. All checks are transited, the user specified all data, we can create object for saving in a DB - what information will not suffice us?