Implementing Search method For a Class In my web app, I have a view where users can search in receipts and drafts.

I've implemented this ability in search method at my view model, but I'm not sure if this is the best place to put it. So I'll let you take a look at it.

public class ProductCardSearchViewModel
{
    public IEnumerable&lt;ProductCardRowViewModel&gt; Search()
    {
        GenericRepository&lt;Rows&gt; repo = new GenericRepository&lt;Rows&gt;();
        var temp = repo.GetAll();

        if (this.Warehouse != 0)
            temp = temp.Where(x =&gt; x.Head.Warehouse == this.Warehouse );
        if (ProductCode &gt; 0)
            temp = temp.Where(x =&gt; x.ProductCode == this.ProductCode );
        if (!string.IsNullOrEmpty(this.UnitCode))
            temp = temp.Where(x =&gt; x.UnitCode .Equals(this.UnitCode));

        List&lt;ProductCardRowViewModel&gt; data = new List&lt;ProductCardRowViewModel&gt;();

        foreach (Rows row in temp)
            data.Add(new ProductCardRowViewModel(row));

        return data;
    }

    [Display(Name = "")]
    public long Warehouse { get; set; }

    [Display(Name = "")]
    public string UnitCode { get; set; }

    [Display(Name = "")]
    public long ProductCode { get; set; }
}


Please feel free to suggest any improvements in this code. I'm not much interested to stick with design patterns, but I like to have SOLID code, and I'm kind of sure that this one is not!
public IEnumerable&lt;ProductCardRowViewModel&gt; Search()
{
    GenericRepository&lt;Rows&gt; repo = new GenericRepository&lt;Rows&gt;();
    var temp = repo.GetAll();

    if (this.Warehouse != 0)
        temp = temp.Where(x =&gt; x.Head.Warehouse == this.Warehouse );
    if (ProductCode &gt; 0)
        temp = temp.Where(x =&gt; x.ProductCode == this.ProductCode );
    if (!string.IsNullOrEmpty(this.UnitCode))
        temp = temp.Where(x =&gt; x.UnitCode .Equals(this.UnitCode));

    List&lt;ProductCardRowViewModel&gt; data = new List&lt;ProductCardRowViewModel&gt;();

    foreach (Rows row in temp)
        data.Add(new ProductCardRowViewModel(row));

    return data;
}  




omitting braces {} in places where they are optional is bad practice and leads to error prone code.  
in its current state this method is returning for Warehouse == 0, ProductCode == 0 and for instance UnitCode == string.Empty all items. If this is what you want then IMO a comment should describe this behaviour.  
you are sometimes using this and sometimes you don't. Choose one style and stick to it.  
I would add a ToList() to temp in the loop. And by the way temp is a really bad name.  
instead of building the returned value as a List&lt;T&gt; you could simply use yield return. If you want to keep the List you should at least use var.


Applying the mentioned points would lead to  

public IEnumerable&lt;ProductCardRowViewModel&gt; Search()
{
    GenericRepository&lt;Rows&gt; repo = new GenericRepository&lt;Rows&gt;();
    var rows = repo.GetAll();

    if (this.Warehouse != 0)
    {
        rows = rows.Where(x =&gt; x.Head.Warehouse == this.Warehouse );
    }

    if (this.ProductCode &gt; 0)
    {
        rows = rows.Where(x =&gt; x.ProductCode == this.ProductCode );
    }

    if (!string.IsNullOrEmpty(this.UnitCode))
    {
        rows = rows.Where(x =&gt; x.UnitCode.Equals(this.UnitCode));
    }

    foreach (Rows row in rows.ToList())
    {
        yield return new ProductCardRowViewModel(row);
    }
}