Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't figure out what I am doing wrong Lecture 176 #5

Closed
althepal78 opened this issue Sep 5, 2022 · 1 comment
Closed

I can't figure out what I am doing wrong Lecture 176 #5

althepal78 opened this issue Sep 5, 2022 · 1 comment

Comments

@althepal78
Copy link

althepal78 commented Sep 5, 2022

I don't know what happened in this section,
<input value="@Model.OrderHeader.OrderDate.ToShortDateString()" readonly type="text" class="form-control" /> on my details page I get this error and it just started. I don't know how the reference is null if it i showing properly on the page
System.NullReferenceException: 'Object reference not set to an instance of an object.', Yet you can see it working properly before I press the update order details button. I can't figure out why it is null and I am getting frustrated because I just got here and figured out everything else I had errors with. I have it on this repository https://github.com/althepal78/MellysUnderGroundCuisineMUCDB
because I am going to change it from book to my friends site ;)

@althepal78
Copy link
Author

althepal78 commented Sep 5, 2022

This is what I had to do to make this work. I wish people would answer. It was more of a mess up in the payment thing so it ruined everything.

  public IActionResult OrderConfirmation(Guid id)
        {
            OrderHeader orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == id, includeProperties: "ApplicationUser");
            if (orderHeader.PaymentStatus != StaticDetails.PaymentStatusDelayedPayment)
            {
                var service = new SessionService();
                Session session = service.Get(orderHeader.SessionId);
                
                if(orderHeader.PaymentIntentId == null)
                {
                    orderHeader.PaymentIntentId = session.PaymentIntentId;
                    _unitOfWork.OrderHeader.Update(orderHeader);
                    _unitOfWork.Save();
                }
                //check the stripe status
                if (session.PaymentStatus.ToLower() == "paid")
                {
                    _unitOfWork.OrderHeader.UpdateStatus((Guid)id, StaticDetails.StatusApproved, StaticDetails.PaymentStatusApproved);
                    _unitOfWork.Save();
                }
            }
            
            _emailSender.SendEmailAsync(orderHeader.ApplicationUser.Email, "New Order - Bulky Book", "<p>New Order Created</p>");
            List<ShoppingCart> shoppingCarts = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId ==
            orderHeader.ApplicationUserId).ToList();
            _unitOfWork.ShoppingCart.RemoveRange(shoppingCarts);
            _unitOfWork.Save();
            return View((Guid)id);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant