i am aware of how to to convert if-else with single conditions in each if with design pattern. but now i am little bit confuse because in my code there are multiple condition separated by && operator in if. now how to refactor such type of cases.
code is as per below:
public ActionResult PaymentDetails(PaymentlistingDTOVM model, string SearchButton)
{
PaymentlistingDTOVM dto = new PaymentlistingDTOVM();
if (model.PaymentSearch == null)
{
ModelState.AddModelError("Message", "Please select type to search ( Member No / Member Name).");
}
else if (model.PaymentSearch == "1" && model.Memberno == null)
{
ModelState.AddModelError("Message", "Please Enter Member No.");
}
else if (model.PaymentSearch == "2" && model.MemberName == null)
{
ModelState.AddModelError("Message", "Please Enter Member Name.");
}
else
{
if (!string.IsNullOrEmpty(model.SearchButton) || model.Page.HasValue)
{
if (model.Memberno != null)
{
var Listpay = objIPaymentlisting.AllPaymentDetails(Convert.ToString(model.Memberno));
var results = Listpay.Where(p => (p.MemberID == model.Memberno));
var pageIndex = model.Page ?? 1;
model.SearchResults = results.ToPagedList(pageIndex, RecordsPerPage);
}
else if (model.MemberName != null)
{
string[] Memno = model.MemberName.Split('|');
var Listpay = objIPaymentlisting.AllPaymentDetails(Convert.ToString(Memno[3]));
var results = Listpay.Where(p => (p.MemberID == Convert.ToInt32(Memno[3])));
var pageIndex = model.Page ?? 1;
model.SearchResults = results.ToPagedList(pageIndex, RecordsPerPage);
}
}
}
return View(model);
}
Aucun commentaire:
Enregistrer un commentaire