Files
yavsc/Yavsc/Helpers/ListItemHelpers.cs
2016-06-12 01:32:51 +02:00

28 lines
882 B
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.Rendering;
using Yavsc.Models;
namespace Yavsc.Helpers {
public static class ListItemHelpers {
public static List<SelectListItem> ActivityItems(
this ApplicationDbContext _dbContext, string selectedCode)
{
var codeIsNull = (string.IsNullOrEmpty(selectedCode));
List<SelectListItem> items;
if (codeIsNull) items = _dbContext.Activities.Select(
x=> new SelectListItem() {
Value=x.Code, Text=x.Name
} ).ToList();
else items =
_dbContext.Activities.Select(
x=> new SelectListItem() {
Value=x.Code, Text=x.Name,
Selected = (x.Code == selectedCode)
} ).ToList();
return items;
}
}
}