public IActionResult SaveOrder() { var sessionusername = (int)HttpContext.Session.GetInt32("UserId"); var defaultAddress = AddressHelper.GetAddressByDefaultId(); var defaultPayment = PaymentHelper.GetPaymentByDefaultId(); var defaultUser = UserHelper.GetUserInfoById(sessionusername); dm.Orders user = new dm.Orders { User = defaultUser }; var getProduct = JsonConvert.DeserializeObject <List <OrderAndPaymentViewModel> >(HttpContext.Session.GetString("ProductTime")); List <dm.Orders> finalOrderModel = new List <dm.Orders>(); string guid = System.Guid.NewGuid().ToString(); foreach (var item in getProduct) { var model = new ConversionOrder(); finalOrderModel.Add(model.MappingOrders(item)); } foreach (var item in finalOrderModel) { var currentListing = ListingHelper.GetListingInfoByIdForOrder(item); item.OrderGroupNumber = guid; item.ShippingStatus = "Pending"; //item.Timestamp = GetTimestamp(DateTime.Now); item.User = defaultUser; item.Payment = defaultPayment; item.Payment.User = defaultUser; item.Listing = currentListing; item.Listing.User = defaultUser; item.Listing.ProductInfo = currentListing.ProductInfo; item.Listing.ProductInfo.Brand = currentListing.ProductInfo.Brand; item.Listing.ProductInfo.Type = currentListing.ProductInfo.Type; } foreach (var item in finalOrderModel) { var result = OrderHelper.AddOrderById(item); ListOfProducts.RemoveAll(p => p.ProductInfoId > 0); //if (result) //{ // ListingHelper.UpdateQuantityById(item.Listing); //} } return(RedirectToAction("Account", "Home")); }
public void Test_GetListingInfoByIdForOrder() { Orders order = new Orders { OrderId = 43, Listing = new Listing { ListingId = 41, ProductInfo = new ProductInfo { ProductInfoId = 17, } } }; var sut = ListingHelper.GetListingInfoByIdForOrder(order); Assert.NotNull(sut); }