using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using WalkingTec.Mvvm.Core; using HHWMS.Web.Models; namespace HHWMS.Web { public class LocationMonitor2DVM : BaseVM { public string Area { get; set; } public string Row { get; set; } public class LocationGridItem { public string Code { get; set; } public short Row { get; set; } public short Line { get; set; } public short Layer { get; set; } public LocationStatusEnum Status { get; set; } public string ContainerCode { get; set; } } public IEnumerable GetAreas() { return DC.Set() .Select(x => x.ZoneId) .Distinct() .OrderBy(x => x) .ToList(); } public IEnumerable GetRows(int area) { return DC.Set() .Where(x => x.ZoneId == area) .Select(x => x.Row) .Distinct() .OrderBy(x => x) .ToList(); } public IEnumerable GetLocationsByAreaAndRow(int area, short row) { var result = DC.Set() .Where(x => x.ZoneId == area && x.Row == row) .OrderBy(x => x.Line) .Select(x => new { Code = x.Code, Row = x.Row, Line = x.Line, Layer = x.Layer, x.Status, Status1 = x.Status.GetEnumDisplayName(), ContainerCode = x.ContainerCode }).ToList(); return result; } private string GetEnumDisplayName(Enum enumValue) { var fieldInfo = enumValue.GetType().GetField(enumValue.ToString()); var displayAttribute = fieldInfo.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault() as DisplayAttribute; return displayAttribute?.Name ?? enumValue.ToString(); } } }