نسخه 5.0.1 این زیرساخت مبتنیبر .NET 5 منتشر شد!
۳ سال و ۶ ماه قبل، شنبه ۲۳ اسفند ۱۳۹۹، ساعت ۱۳:۳۸
public class Customer { public string Email { get; private set; } public string Name { get; private set; } private Customer(email, name) { Email = email; Name = name; } public static Result<Customer> New(string email, string name, INewCustomerPolicy policy) { var isUnique = policy.IsUnique(email); if (!isUnique) { return Result.Fail<Customer>("Customer with this email already exists."); } var customer = new Customer(email, name); //customer.AddDomainEvent(new CustomerRegistered(customer)); return Result.Ok(customer); } }
public class UserModel { [MaxLength(200)] [Display(Name = "Full name")] [Required] public string Name { get; set; } } public class UserModalViewModel { public UserModel Model { get; set; } public bool IsAdmin { get; set; } public IReadonlyList<lookupitem> Roles { get; set; } }
[HttpGet] public async Task<IActionResult> Edit(int id) { var user = await _service.FindAsync(id); //return Maybe<UserModel> if (!user.HasValue) { return NotFound(); } // prepare model var model = new UserModalViewModel { Model = user.Value, IsAdmin = true, Roles = await _lookupService.ReadRolesAsync() }; return View(model); }
[HttPost] public async Task<IActionResult> Edit([Bind(Prefix = "Model")] UserModel model) { //todo: check ModelState and save model await _service.EditAsync(model); }
A next-level validation is domain validation, or as I've often seen referred, "business rule validation". This is more of a system state validation, "can I affect the change to my system based on the current state of my system". I might be checking the state of a single entity, a group of entities, an entire collection of entities, or the entire system. The key here is I'm not checking the request against itself, but against the system state.