public ActionResult RefreshItem(OrderItemVm item) { var cartCookie = CheckCart(); if (cartCookie.Value != "") { var listItems = JsonConvert.DeserializeObject <List <OrderItemVm> >(cartCookie.Value); listItems.Where(x => x.Guid == item.Guid).First().Quantity = item.Quantity; if (listItems.Count > 0) { cartCookie.Value = JsonConvert.SerializeObject(listItems); cartCookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Set(cartCookie); return(Json(new { Status = true })); } cartCookie.Expires = DateTime.Now.AddDays(-180); Response.Cookies.Add(cartCookie); } return(Json(new { Status = false })); }
public async Task <IActionResult> Get(long id) { var order = _orderRepository .Query() .Include(x => x.ShippingAddress).ThenInclude(x => x.District) .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince) .Include(x => x.ShippingAddress).ThenInclude(x => x.Country) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option) .Include(x => x.CreatedBy) .FirstOrDefault(x => x.Id == id); if (order == null) { return(new NotFoundResult()); } var currentUser = await _workContext.GetCurrentUser(); if (!User.IsInRole("admin") && order.VendorId != currentUser.VendorId) { return(new BadRequestObjectResult(new { error = "You don't have permission to manage this order" })); } var model = new OrderDetailVm { Id = order.Id, CreatedOn = order.CreatedOn, OrderStatus = (int)order.OrderStatus, OrderStatusString = order.OrderStatus.ToString(), CustomerName = order.CreatedBy.FullName, Subtotal = order.SubTotal, Discount = order.Discount, SubTotalWithDiscount = order.SubTotalWithDiscount, ShippingAddress = new ShippingAddressVm { AddressLine1 = order.ShippingAddress.AddressLine1, AddressLine2 = order.ShippingAddress.AddressLine2, ContactName = order.ShippingAddress.ContactName, DistrictName = order.ShippingAddress.District?.Name, StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name, Phone = order.ShippingAddress.Phone }, OrderItems = order.OrderItems.Select(x => new OrderItemVm { Id = x.Id, ProductName = x.Product.Name, ProductPrice = x.ProductPrice, ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), Quantity = x.Quantity, VariationOptions = OrderItemVm.GetVariationOption(x.Product) }).ToList() }; return(Json(model)); }
public IActionResult Get(long id) { var order = _orderRepository .Query() .Include(x => x.ShippingAddress).ThenInclude(x => x.Address).ThenInclude(x => x.District).ThenInclude(x => x.StateOrProvince) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option) .Include(x => x.CreatedBy) .FirstOrDefault(x => x.Id == id); if (order == null) { return(new NotFoundResult()); } var model = new OrderDetailVm { Id = order.Id, CreatedOn = order.CreatedOn, OrderStatus = (int)order.OrderStatus, OrderStatusString = order.OrderStatus.ToString(), CustomerName = order.CreatedBy.FullName, SubTotal = order.SubTotal, ShippingAddress = new ShippingAddressVm { AddressLine1 = order.ShippingAddress.Address.AddressLine1, AddressLine2 = order.ShippingAddress.Address.AddressLine2, ContactName = order.ShippingAddress.Address.ContactName, DistrictName = order.ShippingAddress.Address.District.Name, StateOrProvinceName = order.ShippingAddress.Address.StateOrProvince.Name, Phone = order.ShippingAddress.Address.Phone }, OrderItems = order.OrderItems.Select(x => new OrderItemVm { Id = x.Id, ProductName = x.Product.Name, ProductPrice = x.ProductPrice, ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), Quantity = x.Quantity, VariationOptions = OrderItemVm.GetVariationOption(x.Product) }).ToList() }; return(Json(model)); }
public ActionResult Order(OrderItemVm item) { var cartCookie = CheckCart(); if (item.FromDate.Date < DateTime.Now.Date) { return(Json(new { Status = false })); } if (cartCookie.Value != "") { var listItems = JsonConvert.DeserializeObject <List <OrderItemVm> >(cartCookie.Value); if (listItems.Any(x => x.Alias == item.Alias && x.FromDate == item.FromDate)) { listItems.First(x => x.Alias == item.Alias && x.FromDate == item.FromDate).Quantity++; } else { item.Quantity = 1; item.Guid = Guid.NewGuid().ToString(); listItems.Add(item); } cartCookie.Value = JsonConvert.SerializeObject(listItems); cartCookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Set(cartCookie); } else { var listItems = new List <OrderItemVm>(); item.Quantity = 1; item.Guid = Guid.NewGuid().ToString(); listItems.Add(item); cartCookie.Value = JsonConvert.SerializeObject(listItems); cartCookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(cartCookie); } return(Json(new { Status = true })); }
public async Task <IActionResult> Print(long id) { var order = await _orderRepository .Query() .Include(x => x.ShippingAddress).ThenInclude(x => x.District) .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince) .Include(x => x.ShippingAddress).ThenInclude(x => x.Country) .Include(x => x.OrderItems).ThenInclude(x => x.Product) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option) .Include(x => x.CreatedBy) .FirstOrDefaultAsync(x => x.Id == id); if (order == null) { return(NotFound()); } var currentUser = await _workContext.GetCurrentUser(); if (!User.IsInRole("admin") && order.VendorId != currentUser.VendorId) { return(BadRequest(new { error = "You don't have permission to manage this order" })); } var model = new OrderDetailVm { Id = order.Id, CreatedOn = order.CreatedOn, OrderStatus = (int)order.OrderStatus, OrderStatusString = order.OrderStatus.ToString(), CustomerId = order.CreatedById, CustomerName = order.CreatedBy.FullName, CustomerEmail = order.CreatedBy.Email, ShippingMethod = order.ShippingMethod, PaymentMethod = order.PaymentMethod, PaymentFeeAmount = order.PaymentFeeAmount, Subtotal = order.SubTotal, DiscountAmount = order.DiscountAmount, SubTotalWithDiscount = order.SubTotalWithDiscount, TaxAmount = order.TaxAmount, ShippingAmount = order.ShippingFeeAmount, OrderTotal = order.OrderTotal, ShippingAddress = new ShippingAddressVm { AddressLine1 = order.ShippingAddress.AddressLine1, AddressLine2 = order.ShippingAddress.AddressLine2, ContactName = order.ShippingAddress.ContactName, DistrictName = order.ShippingAddress.District?.Name, StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name, Phone = order.ShippingAddress.Phone }, OrderItems = order.OrderItems.Select(x => new OrderItemVm { Id = x.Id, ProductId = x.Product.Id, ProductName = x.Product.Name, ProductPrice = x.ProductPrice, Quantity = x.Quantity, DiscountAmount = x.DiscountAmount, TaxAmount = x.TaxAmount, TaxPercent = x.TaxPercent, VariationOptions = OrderItemVm.GetVariationOption(x.Product) }).ToList() }; var invoiceHtml = await _viewRender.RenderViewToStringAsync("/Modules/SimplCommerce.Module.Orders/Views/Shared/InvoicePdf.cshtml", model); byte[] pdf = _pdfConverter.Convert(invoiceHtml); return(new FileContentResult(pdf, "application/pdf")); }
public async Task <IActionResult> Get(long id) { var order = _orderRepository .Query() .Include(x => x.ShippingAddress).ThenInclude(x => x.District) .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince) .Include(x => x.ShippingAddress).ThenInclude(x => x.Country) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option) .Include(x => x.CreatedBy) .FirstOrDefault(x => x.Id == id); if (order == null) { return(NotFound()); } var currentUser = await _workContext.GetCurrentUser(); if (!User.IsInRole("admin") && order.VendorId != currentUser.VendorId) { return(BadRequest(new { error = "You don't have permission to manage this order" })); } var model = new OrderDetailVm { Id = order.Id, IsMasterOrder = order.IsMasterOrder, CreatedOn = order.CreatedOn, OrderStatus = (int)order.OrderStatus, OrderStatusString = order.OrderStatus.ToString(), CustomerId = order.CreatedById, CustomerName = order.CreatedBy.FullName, CustomerEmail = order.CreatedBy.Email, ShippingMethod = order.ShippingMethod, PaymentMethod = order.PaymentMethod, PaymentFeeAmount = order.PaymentFeeAmount, Subtotal = order.SubTotal, DiscountAmount = order.DiscountAmount, SubTotalWithDiscount = order.SubTotalWithDiscount, TaxAmount = order.TaxAmount, ShippingAmount = order.ShippingFeeAmount, OrderTotal = order.OrderTotal, ShippingAddress = new ShippingAddressVm { AddressLine1 = order.ShippingAddress.AddressLine1, AddressLine2 = order.ShippingAddress.AddressLine2, ContactName = order.ShippingAddress.ContactName, DistrictName = order.ShippingAddress.District?.Name, StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name, Phone = order.ShippingAddress.Phone }, OrderItems = order.OrderItems.Select(x => new OrderItemVm { Id = x.Id, ProductId = x.Product.Id, ProductName = x.Product.Name, ProductPrice = x.ProductPrice, Quantity = x.Quantity, DiscountAmount = x.DiscountAmount, TaxAmount = x.TaxAmount, TaxPercent = x.TaxPercent, VariationOptions = OrderItemVm.GetVariationOption(x.Product) }).ToList() }; if (order.IsMasterOrder) { model.SubOrderIds = _orderRepository.Query().Where(x => x.ParentId == order.Id).Select(x => x.Id).ToList(); } await _mediator.Publish(new OrderDetailGot { OrderDetailVm = model }); return(Json(model)); }
public async Task <IActionResult> OrderDetails(long orderId) { var user = await _workContext.GetCurrentUser(); var order = _orderRepository .Query() .Include(x => x.ShippingAddress).ThenInclude(x => x.District) .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince) .Include(x => x.ShippingAddress).ThenInclude(x => x.Country) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option) .Include(x => x.Customer) .FirstOrDefault(x => x.Id == orderId); if (order == null) { return(NotFound()); } if (order.CustomerId != user.Id) { return(BadRequest(new { error = "You don't have permission to view this order" })); } var model = new OrderDetailVm(_currencyService) { Id = order.Id, IsMasterOrder = order.IsMasterOrder, CreatedOn = order.CreatedOn, OrderStatus = (int)order.OrderStatus, OrderStatusString = order.OrderStatus.ToString(), CustomerId = order.CustomerId, CustomerName = order.Customer.FullName, CustomerEmail = order.Customer.Email, ShippingMethod = order.ShippingMethod, PaymentMethod = order.PaymentMethod, PaymentFeeAmount = order.PaymentFeeAmount, Subtotal = order.SubTotal, DiscountAmount = order.DiscountAmount, SubTotalWithDiscount = order.SubTotalWithDiscount, TaxAmount = order.TaxAmount, ShippingAmount = order.ShippingFeeAmount, OrderTotal = order.OrderTotal, OrderNote = order.OrderNote, ShippingAddress = new ShippingAddressVm { AddressLine1 = order.ShippingAddress.AddressLine1, CityName = order.ShippingAddress.City, ZipCode = order.ShippingAddress.ZipCode, ContactName = order.ShippingAddress.ContactName, DistrictName = order.ShippingAddress.District?.Name, StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name, Phone = order.ShippingAddress.Phone }, OrderItems = order.OrderItems.Select(x => new OrderItemVm(_currencyService) { Id = x.Id, ProductId = x.Product.Id, ProductName = x.Product.Name, ProductPrice = x.ProductPrice, Quantity = x.Quantity, DiscountAmount = x.DiscountAmount, ProductImage = x.Product.ThumbnailImage.FileName, TaxAmount = x.TaxAmount, TaxPercent = x.TaxPercent, VariationOptions = OrderItemVm.GetVariationOption(x.Product) }).ToList() }; foreach (var item in model.OrderItems) { item.ProductImage = _mediaService.GetMediaUrl(item.ProductImage); } return(View(model)); }