Question

I have is_valid attribute in almost all of my model. I want to update is_valid attribute of any objects which contains this attribute ?

How can i do this ? Should i learn repository pattern ?

One of my model as seen as below :

public class HrFileType
{
    public int Id { get; set; }

    [Display(Name = "Dosya Tipinin Adı")]
    [Required]
    public String Name { get; set; }

    [Display(Name = "İkaz Periyodu(Gün)")]        
    public Int64? NotificationPeriod { get; set; }

    [Display(Name = "Açıklama")]
    public string Note { get; set; }

    public bool is_valid { get; set; }

    public virtual ICollection<HrMapPersonFile> HrMapPersonFile { get; set; }

}
Was it helpful?

Solution

Most straight forward approach:

public class BaseModel 
{
    public bool is_valid { get; set; }
}

public class HrFileType : BaseModel 
{
    public int Id { get; set; }

    [Display(Name = "Dosya Tipinin Adı")]
    [Required]
    public String Name { get; set; }

    [Display(Name = "İkaz Periyodu(Gün)")]        
    public Int64? NotificationPeriod { get; set; }

    [Display(Name = "Açıklama")]
    public string Note { get; set; }

    public virtual ICollection<HrMapPersonFile> HrMapPersonFile { get; set; }

}

And your Update method can be:

void markValid(BaseModel model)
{
    model.is_valid = true;
}

Update:

For your File Upload case: Create another Base Class:

public class FileUploadBaseModel : BaseModel
{
    //properties you need for file upload
}

And in your model that need fileupload:

public class SomeModelName: FileUploadBaseModel 
{
    //properties specific for this model
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top