Changeset fa0fbaf for KernelRecordsMVC.Web/Controllers/OrderController.cs
- Timestamp:
- 09/01/26 06:11:34 (4 weeks ago)
- Branches:
- main
- Children:
- d2eccb3
- Parents:
- 08aefc6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
KernelRecordsMVC.Web/Controllers/OrderController.cs
r08aefc6 rfa0fbaf 1 using Microsoft.AspNetCore.Http;2 3 namespace KernelRecordsMVC.Controllers;4 1 using KernelRecordsMVC.Application.ViewModels; 2 using KernelRecordsMVC.Domain.Enums; 3 using KernelRecordsMVC.Infrastructure.Data; 4 using KernelRecordsMVC.Models; 5 5 using Microsoft.AspNetCore.Mvc; 6 6 using Microsoft.EntityFrameworkCore; 7 using KernelRecordsMVC.Data; 8 using KernelRecordsMVC.Models; 9 using KernelRecordsMVC.Domain.Enums; 10 using KernelRecordsMVC.Application.ViewModels; 7 8 namespace KernelRecordsMVC.Web.Controllers; 11 9 12 10 public class OrderController : Controller … … 67 65 order = new Order 68 66 { 69 OrderId = GetNextOrderId(),70 67 UserId = userId.Value, 71 72 // The actual payment method will be73 // selected during checkout.74 68 PaymentMethod = PaymentMethodType.CARD, 75 76 69 PurchaseDate = DateTime.Today, 77 78 70 PointsEarned = 0, 79 80 71 PointsUsed = null, 81 82 72 Status = OrderStatusType.PENDING 83 73 }; … … 113 103 else 114 104 { 105 var discount = _context.ModificationProducts 106 .Include(mp => mp.Modification) 107 .Where(mp => 108 mp.ProductId == product.ProductId && 109 mp.Modification.TypeOfModification == 110 ModificationType.DISCOUNT && 111 mp.Modification.Discount.HasValue && 112 mp.Modification.Discount.Value > 0) 113 .Select(mp => mp.Modification) 114 .OrderByDescending(m => m.DateModified) 115 .FirstOrDefault(); 116 117 var priceAtPurchase = product.Price; 118 119 if (discount != null) 120 { 121 priceAtPurchase = 122 product.Price - 123 (product.Price * discount.Discount!.Value / 100m); 124 125 priceAtPurchase = Math.Round( 126 priceAtPurchase, 127 2); 128 } 129 115 130 var orderProduct = new OrderProduct 116 131 { … … 186 201 187 202 Stock = 188 op.Product.Stock 203 op.Product.Stock, 204 205 CoverPhoto = op.Product.Release.CoverPhoto 189 206 }) 190 207 .ToList(); … … 294 311 private long? GetUserId() 295 312 { 296 var value = 297 HttpContext.Session.GetString("UserId"); 298 299 if (long.TryParse(value, out var userId)) 300 return userId; 313 var userId = HttpContext.Session.GetInt32("UserId"); 314 315 if (userId.HasValue) 316 return userId.Value; 301 317 302 318 return null; 303 319 } 304 305 306 // ==========================================307 // ORDER ID308 // ==========================================309 310 private long GetNextOrderId()311 {312 var maxId = _context.Orders313 .Select(x => (long?)x.OrderId)314 .Max();315 316 return (maxId ?? 0) + 1;317 }318 320 }
Note:
See TracChangeset
for help on using the changeset viewer.
