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<ProductCardRowViewModel> Search()
{
GenericRepository<Rows> repo = new GenericRepository<Rows>();
var temp = repo.GetAll();
if (this.Warehouse != 0)
temp = temp.Where(x => x.Head.Warehouse == this.Warehouse );
if (ProductCode > 0)
temp = temp.Where(x => x.ProductCode == this.ProductCode );
if (!string.IsNullOrEmpty(this.UnitCode))
temp = temp.Where(x => x.UnitCode .Equals(this.UnitCode));
List<ProductCardRowViewModel> data = new List<ProductCardRowViewModel>();
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!
S. I don't see any inheritance, so theOdoesn't apply. Same thing for theL. I don't see any monster interfaces, so theIdoesn't apply. The one problem I see is that you new up a GenericRepository<Rows>. This violates theD. That dependency should be injected. \$\endgroup\$