문제

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; }

}
도움이 되었습니까?

해결책

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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top