mardi 8 août 2017

Clean Code for If Statement

I have a statement like this, how can i optimize this logic. I think about 1 hour but i dont find.

How can i simplfy this logic ?

if (model.WaitingChecked) 
{
    if (model.selectedStatus != 0) 
    {
        model.DataList = data.Where(x => x.status != 6 && x.status == model.selectedStatus);
        return View(model);
    }

    model.DataList = data.Where(x => x.status != 6);
    return View(model);
}

if (model.SelectedStatus != 0) 
{
    model.DataList = data.Cast<DataDetailedList>().Where(x => x.status == model.selectedStatus);
    return View(model);
}

Aucun commentaire:

Enregistrer un commentaire