public List<RawMaterial> GetRawMaterialInfo()
{
using (dbContext = new tPOS_DBEntities())
{
var data = from p in dbContext.RawMaterials
join q in dbContext.UnitOfMeasures on p.UOM_Receive equals q.Code into rcvUOM
from a in rcvUOM.DefaultIfEmpty()
join r in dbContext.UnitOfMeasures on p.UOM_Stock equals r.Code into stkUOM
from b in stkUOM.DefaultIfEmpty()
join s in dbContext.RawMaterials on p.ParentCode equals s.Code
select new
{
p.Code,
p.ConvertionRate,
p.CreatedBy,
p.CreatedDate,
p.DriesPrcnt,
p.ID,
p.Level,
p.Name,
p.NonExpireItem,
p.NonInvItem,
p.ParentCode,
RecvUOM = a.UOM,
p.ROL,
p.ROQ,
p.StdCPU,
p.StockCPU,
StockUOM = b.UOM,
p.SysCode,
p.UOM_Receive,
p.UOM_Stock,
p.UpdatedBy,
p.UpdatedDate,
ParentName = s.Name
};
List<RawMaterial> lst = new List<RawMaterial>();
RawMaterial l;
foreach (var d in data)
{
l = new RawMaterial();
l.Code = d.Code;
l.ConvertionRate = d.ConvertionRate;
l.CreatedBy = d.CreatedBy;
l.CreatedDate = d.CreatedDate;
l.DriesPrcnt = d.DriesPrcnt;
l.ID = d.ID;
l.Level = d.Level;
l.Name = d.Name;
l.NonExpireItem = d.NonExpireItem;
l.NonInvItem = d.NonInvItem;
l.ParentCode = d.ParentCode;
l.ParentName = d.ParentName;
l.RecvUOM = d.RecvUOM;
l.ROL = d.ROL;
l.ROQ = d.ROQ;
l.StdCPU = d.StdCPU;
l.StockCPU = d.StockCPU;
l.StockUOM = d.StockUOM;
l.SysCode = d.SysCode;
l.UOM_Receive = d.UOM_Receive;
l.UOM_Stock = d.UOM_Stock;
l.UpdatedBy = d.UpdatedBy;
l.UpdatedDate = d.UpdatedDate;
if (l.ParentName != null)
{
l.FullName = (l.ParentName.Trim().Length != 0 ? l.ParentName + "::" : "") + l.Name;
}
else
{
l.FullName = l.Name;
}
lst.Add(l);
}
return lst.OrderBy(p => p.ParentName).OrderBy(p => p.Name).ToList();
}
}