Esempio n. 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);
        }
Esempio n. 2
0
        public IActionResult CancelBill(int billId)
        {
            //get credential
            CredentialModel credential = HttpContext.Session.GetObject <CredentialModel>(Constants.VM);
            //get token
            string token = credential.JwToken;

            // get bill and billdetail
            Bill bill = GetApiMyBills.GetBills(credential).SingleOrDefault(p => p.BillId == billId);
            List <BillDetailModel> billDetails = GetBills().SingleOrDefault(p => p.BillId == bill.BillId).BillDetail;

            // Update status for bill want to be canceled
            bill.IsCancel = true;
            UpdateBill(bill, credential);

            // update amount
            foreach (var detail in billDetails)
            {
                if (IsFood(detail.ProductId))
                {
                    FoodProduct food = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == detail.ProductId);
                    food.FoodAmount += detail.Amount;
                    GetApiFoodProducts.UpdateStock(food, token);
                }
                else if (IsToy(detail.ProductId))
                {
                    ToyProduct toy = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == detail.ProductId);
                    toy.ToyAmount += detail.Amount;
                    GetApiToyProducts.UpdateStock(toy, token);
                }
                else
                {
                    CostumeProduct costume = GetApiCostumeProducts.GetCostumeProducts().SingleOrDefault(p => p.ProductId == detail.ProductId && p.CostumeSize == detail.NoteSize);
                    costume.CostumeAmountSize += detail.Amount;
                    GetApiCostumeProducts.UpdateStock(costume, token);
                }
            }

            return(RedirectToAction("Index"));
        }