Asp.Net MVC2 TekPub Initial question of site methodology

Well, I just stumbled upon this and I had to check my emails, but I ended up watching this (and not far off subscribed to TekPub).

http://tekpub.com/production/starter

Now this application is a great starting point, but for me there is one problem, and the development process, which I was shown, matches (right or wrong). When transferring data to a view, there is no conversion of the LinqToSql object. Are there any negatives?

The main problem that I see is checking if this causes problems when using the MVCs built into the check, as this is what we use extensively. Since we use the built-in objects created by LinqToSql, how could a check be added, for example

[Required(ErrorMessage="Name is Required")]
public string Name {get;set;}

We are interested in understanding the advantages of this methodology and any negatives that, if we take it upon ourselves, through the development process.

Should this be taken as a guide and should we use ViewModels? If so, will we always use them even in simple cases? And how / where in the application logic is Entity converted to ViewModel?

+3
source share
1 answer

, , . , Customer, Linq-to-Sql, :

[MetadataType(typeof(CustomerMeta))]
partial class Customer {

}

public class CustomerMeta {

  [DisplayName("Forename", Required(ErrorMessage = "Forename is required.")]
  public string Forename { get; set;}
}

, .

, , User, , -, CreateUserSpec :

public class CreateUserSpec
{
  [DisplayName("Forename")]
  public string Forename { get; set; }
}

, , . , , . :

public class AccountController
{
  public ActionResult Register() {
    return View(new CreateUserSpec());
  }

  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult Register(CreateUserSpec spec) {
    if (!ModelState.IsValid) {
      return View(spec);
    }

    var user = UserFactory.CreateUser(spec);

    // Redirect to authorisation page?
  }
}
+1

Source: https://habr.com/ru/post/1748917/


All Articles