示例#1
0
        public List <BillModelView> GetBills()
        {
            //get credential
            CredentialModel credential = HttpContext.Session.GetObject <CredentialModel>(Constants.VM);
            // get profile
            UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == credential.AccountUserName);

            // get all Bill with profileID from server
            List <BillModelView> bills = GetApiMyBills.GetBills(credential).Select(p => new BillModelView()
            {
                BillId          = p.BillId,
                BillCode        = p.GenerateCodeCheck,
                DateOfPurchase  = p.DateOfPurchase,
                DateDelivery    = Convert.ToDateTime(p.DateOfDelivered),
                TotalPrice      = p.TotalPrice,
                PaymentMethodId = p.PaymentMethodTypeId,
                IsDelivery      = p.IsDelivery,
                IsCancel        = p.IsCancel,
            }).ToList();

            // get payment method
            foreach (var bill in bills)
            {
                bill.PaymentMethodName = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(p => p.PaymentMethodTypeId == bill.PaymentMethodId).PaymentMethodTypeName;
            }

            // get bill detail
            foreach (var item in bills)
            {
                List <BillDetailModel> details = GetApiBillDetails.GetBillDetails().Where(p => p.BillId == item.BillId)
                                                 .Select(p => new BillDetailModel()
                {
                    ProductId   = p.ProductId,
                    ProductName = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductName,
                    Amount      = p.ProductAmount,
                    Price       = p.ProductPriceCurrent,
                    NoteSize    = p.NoteSize,
                    Image       = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductImage,
                }).ToList();

                item.BillDetail = details;

                // get delivery of bill
                DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == item.BillId);

                // get state of bill
                item.DeliveryProductStateId = delivery.DeliveryProductStateId;

                item.DeliveryStateName = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(p => p.DeliveryProductStateId == delivery.DeliveryProductStateId).DeliveryProductStateName;
            }

            return(bills);
        }
示例#2
0
        public IActionResult BillDetail(int billId)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));

            Bill          p    = GetApiBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId);
            BillModelView bill = new BillModelView()
            {
                BillId            = p.BillId,
                BillCode          = p.GenerateCodeCheck,
                DateOfPurchase    = p.DateOfPurchase,
                DateDelivery      = Convert.ToDateTime(p.DateOfDelivered),
                TotalPrice        = p.TotalPrice,
                PaymentMethodId   = p.PaymentMethodTypeId,
                IsDelivery        = p.IsDelivery,
                IsCancel          = p.IsCancel,
                IsApprove         = p.IsApprove,
                IsCompleted       = p.IsCompleted,
                PaymentMethodName = GetApiPaymentMethodTypes.GetPaymentMethodTypes().SingleOrDefault(k => k.PaymentMethodTypeId == p.PaymentMethodTypeId).PaymentMethodTypeName,
            };

            List <BillDetailModel> details = GetApiBillDetails.GetBillDetails().Where(p => p.BillId == bill.BillId)
                                             .Select(p => new BillDetailModel()
            {
                ProductId   = p.ProductId,
                ProductName = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductName,
                Amount      = p.ProductAmount,
                Price       = p.ProductPriceCurrent,
                NoteSize    = p.NoteSize,
                Image       = GetApiProducts.GetProducts().SingleOrDefault(k => k.ProductId == p.ProductId).ProductImage,
            }).ToList();

            bill.BillDetail = details;

            // get delivery
            DeliveryProduct delivery = GetApiDeliveryProducts.GetDeliveryProducts().SingleOrDefault(p => p.DeliveryProductBillId == bill.BillId);

            bill.delivery = delivery;

            // get state of bill
            bill.DeliveryProductStateId = delivery.DeliveryProductStateId;

            bill.DeliveryStateName = GetApiDeliveryStates.GetDeliveryProductStates().SingleOrDefault(p => p.DeliveryProductStateId == delivery.DeliveryProductStateId).DeliveryProductStateName;

            return(Json(bill));
        }