Search Results

Search found 3 results on 1 pages for 'nabeelfarid'.

Page 1/1 | 1 

  • Sharp architecture; Accessing Validation Results

    - by nabeelfarid
    I am exploring Sharp Architecture and I would like to know how to access the validation results after calling Entity.IsValid(). I have two scenarios e.g. 1) If the entity.IsValid() return false, I would like to add the errors to ModelState.AddModelError() collection in my controller. E.g. in the Northwind sample we have an EmployeesController.Create() action when we do employee.IsValid(), how can I get access to the errors? public ActionResult Create(Employee employee) { if (ViewData.ModelState.IsValid && employee.IsValid()) { employeeRepository.SaveOrUpdate(employee); } // .... } [I already know that when an Action method is called, modelbinder enforces validation rules(nhibernate validator attributes) as it parses incoming values and tries to assign them to the model object and if it can't parse the incoming values  then it register those as errors in modelstate for each model object property. But what if i have some custom validation. Thats why we do ModelState.IsValid first.] 2) In my test methods I would like to test the nhibernate validation rules as well. I can do entity.IsValid() but that only returns true/ false. I would like to Assert against the actual error not just true/ false. In my previous projects, I normally use a wrapper Service Layer for Repositories, and instead of calling Repositories method directly from controller, controllers call service layer methods which in turn call repository methods. In my Service Layer all my custom validation rules resides and Service Layer methods throws a custom exception with a NameValueCollection of errors which I can easily add to ModelState in my controller. This way I can also easily implement sophisticated business rules in my service layer as well. I kow sharp architecture also provides a Service Layer project. But what I am interested in and my next question is: How I can use NHibernate Vaidators to implement sophisticated custom business rules (not just null,empty, range etc.) and make Entity.IsValid() to verify those rules too ?

    Read the article

  • MSBuild.ExtensionPack.FileSystem.Folder with TaskAction="RemoveContent" throws IOException: The dire

    - by nabeelfarid
    Hi guys, I would like to delete all the files and subfolders inside a folder. For this purpose, I am using task in my script with property TaskAction set to "RemoveContent". However there is an inconsistent behaviour. Sometimes when I run the script, it throws IOException with the messsage The directory is not empty. But when i rerun the script it works fine. Any idea why would it be throwing this exception? As I said this does happens occasionally. Regards, Nabeel Farid

    Read the article

  • Fluent Nhibernate Mapping Single class on two database tables

    - by nabeelfarid
    Hi guys, I am having problems with Mapping. I have two tables in my database as follows: Employee and EmployeeManagers Employee EmployeeId int Name nvarchar EmployeeManagers EmployeeIdFk int ManagerIdFk int So the employee can have 0 or more Managers. A manager itself is also an Employee. I have the following class to represent the Employee and Managers public class Employee { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<Employee> Managers { get; protected set; } public Employee() { Managers = new List<Employee>(); } } I don't have any class to represent Manager because I think there is no need for it, as Manager itself is an Employee. I am using autoMapping and I just can't figure out how to map this class to these two tables. I am implementing IAutoMappingOverride for overriding automappings for Employee but I am not sure what to do in it. public class NodeMap : IAutoMappingOverride { public void Override(AutoMapping<Node> mapping) { //mapping.HasMany(x => x.ValidParents).Cascade.All().Table("EmployeeManager"); //mapping.HasManyToMany(x => x.ValidParents).Cascade.All().Table("EmployeeManager"); } } I also want to make sure that an employee can not be assigned the same manager twice. This is something I can verify in my application but I would like to put constraint on the EmployeeManager table (e.g. a composite key) so a same manager can not be assigned to an employee more than once. Could anyone out there help me with this please? Awaiting Nabeel

    Read the article

1