Beispiel #1
0
        public MemberViewModel.MemberListResult GetAll()
        {
            try
            {
                var result = new MemberViewModel.MemberListResult();

                var source       = _dbRepository.GetAll <Member>().AsEnumerable();
                var orders       = _dbRepository.GetAll <Order>().AsEnumerable();
                var products     = _dbRepository.GetAll <Product>().AsEnumerable();
                var orderDetails = _dbRepository.GetAll <OrderDetail>().AsEnumerable().Select(x => new
                {
                    OrderDetailId = x.OrderDetailId,
                    OrderId       = x.OrderId,
                    ProductId     = x.ProductId,
                    Price         = products.FirstOrDefault(y => y.ProductId == x.ProductId)?.UnitPrice ?? 0,
                    Quantity      = x.Quantity
                }).ToList();

                result.MemberList = (from member in source

                                     let orderList = orders.Where(x => x.MemberId == member.MemberId).ToList()
                                                     let orderDetailList = orderDetails.Where(x => orderList.Select(y => y.OrderId).Contains(x.OrderId)).ToList()
                                                                           select new MemberViewModel.MemberSingleResult()
                {
                    memberId = member.MemberId,
                    memberUserName = member.MemberUserName,
                    mobileNumber = member.MobileNumber,
                    homeNumber = member.HomeNumber,
                    address = member.Address,
                    email = member.Email,
                    city = member.City,
                    region = member.Region,
                    memberName = member.MemberName,
                    memberPassword = member.MemberPassword,
                    birthday = member.Birthday,
                    gender = member.Gender,
                    idnumber = member.Idnumber,
                    ordersum = orderDetailList.Sum(y => y.Price * y.Quantity)
                }
                                     ).ToList();



                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine();
                return(new MemberViewModel.MemberListResult());;
            }
        }
 public Task <MemberViewModel.MemberListResult> GetAll()
 {
     return(Task.Run(() =>
     {
         MemberViewModel.MemberListResult result = new MemberViewModel.MemberListResult();
         result.MemberList = _dbRepository.GetAll <Member>().Select(
             m => new MemberViewModel.MemberSingleResult()
         {
             MemberAddress = m.MemberAddress,
             MemberBirth = m.MemberBirth.ToString("d"),
             MemberConEmail = m.MemberConEmail,
             MemberId = m.MemberId,
             MemberName = m.MemberName,
             MemberPhone = m.MemberPhone,
             MemberRegEmail = m.MemberRegEmail,
             MemberWebsite = m.MemberWebsite,
             AboutMe = m.AboutMe,
             Gender = m.Gender,
             ProfileImgUrl = m.ProfileImgUrl,
             MemberTeamName = m.MemberTeamName,
         }).ToList();
         return result;
     }));
 }