public async Task <JsonResult> Create(ShippingInfoViewModel model) { if (!ModelState.IsValid) { return(Json(new { Succeeded = false })); } string trackingId = Guid.NewGuid().ToString(); this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <ShippingOrder>().Add(new ShippingOrder { DestionationAddress = new ShippingDestinationAddress { AddressLine1 = model.ShippingAddressLine1, AddressLine2 = model.ShippingAddressLine2, City = model.ShippingCity, Country = model.ShippingCountry, PostalCode = model.ShippingPostalCode, State = model.ShippingState }, BillingAddress = new ShippingBillingAddress { AddressLine1 = model.BillingAddressLine1, AddressLine2 = model.BillingAddressLine2, City = model.BillingCity, Country = model.BillingCountry, PostalCode = model.BillingPostalCode, State = model.BillingState }, CreationDate = DateTime.Today, Items = model.Items.Select(x => new ShippingItem { Category = x.Category, Name = x.Name, EstimateWeightage = x.EstimatedWeightage, Amount = x.Amount }).ToList(), TrackingId = trackingId, ShipmentOwnerId = this.User.Identity.GetUserId(), Status = ShippingStatus.OrderReceived, }); await this.HttpContext.GetOwinContext().Get <CMSDbContext>().SaveChangesAsync(); return(Json(new { Succeeded = true, TrackingId = trackingId })); }
public ActionResult CheckOut() { if (Session["CURRENT_USER_ID"] != null) { string roleName = Session.GetCurrentUserInfo("RoleName"); if (roleName == "Member") //login { string username = Session.GetCurrentUserInfo("Username"); List <ShoppingItem> cartDB = shoppingService.LoadCartItemDB(username); if (cartDB != null && cartDB.Count != 0) { Dictionary <int, int> IdAndRErrorDB = shoppingService.CheckCartDB(cartDB); if (IdAndRErrorDB.Count == 0) //cart valid { var viewModel = new ShippingInfoViewModel { Total = shoppingService.CalculateCartTotalDB(username) }; return(View("~/Views/User/user_checkout.cshtml", viewModel)); } } return(RedirectToAction("ManageCart", "Home")); } else if (roleName == "Administrator") { return(RedirectToAction("Index", "Admin")); } } //not login ===================================================== //Check if cart existed and not empty List <ShoppingItem> cart = (List <ShoppingItem>)Session["CART"]; if (cart != null && cart.Count != 0) { //Validate cart quantity by session Dictionary <int, int> IdAndRError = shoppingService.CheckCartSession(); if (IdAndRError.Count == 0) //cart valid { return(RedirectToAction("Login", "Account")); } } return(RedirectToAction("ManageCart", "Home")); //đã có validate trong đây }