// GET: Counter public ActionResult Index() { var cus = (from s in db.ServiceAssign from c in db.Customer from n in db.Service where s.NewspaperId == n.Id && s.CustomerId == c.Id select new { Customer = c, ServiceAssign = s, NewsPaper = n }).ToList(); // as IEnumerable<CounterVM>; var uniqCustomer = from m in cus group m by new { m.Customer.Id } into mygroup select mygroup.FirstOrDefault(); List <AccountantVM> objConter = new List <AccountantVM>(); foreach (var item in cus) { AccountantVM counter = new AccountantVM(); counter.Service = item.NewsPaper; counter.Customer = item.Customer; var end = item.ServiceAssign.EndedDate; counter.Endeddate = ADTOBS.EngToNep(end).ToString(); counter.ServiceAssign = item.ServiceAssign; objConter.Add(counter); } return(View(objConter.AsEnumerable())); }
public ActionResult ViewAccount(int?id) { var cus = (from a in db.Account from c in db.Customer from n in db.Service from s in db.ServiceAssign from d in db.SalesMan where a.NewspaperId == n.Id && a.CustomerId == id.Value && a.CustomerId == c.Id && (a.CustomerId == s.CustomerId && a.NewspaperId == s.NewspaperId) && s.SalesManId == d.Id select new { Customer = c, ServiceAssign = s, Account = a, SalesMan = d, NewsPaper = n }).ToList(); // as IEnumerable<CounterVM>; if (cus.Count == 0) { TempData["ErrorMessage"] = "No Record Found."; return(RedirectToAction("index")); } List <AccountantVM> objConter = new List <AccountantVM>(); foreach (var item in cus) { AccountantVM counter = new AccountantVM(); counter.Service = item.NewsPaper; counter.Customer = item.Customer; counter.ServiceAssign = item.ServiceAssign; counter.SalesMan = item.SalesMan; counter.Account = item.Account; objConter.Add(counter); } return(View(objConter.AsEnumerable())); }