示例#1
0
        public async Task <IActionResult> OnPostAsync()
        {
            var username = userManager.GetUserName(User);

            if (username == null)
            {
                return(RedirectToPage("../Index"));
            }
            if (ModifyCart == null)
            {
                return(RedirectToPage("../Index"));
            }
            var cartitem = cartdb.GetById(ModifyCart.GameId, ModifyCart.PlatformId, username);

            if (cartitem == null)
            {
                return(RedirectToPage("../Index"));
            }
            await Task.Run(async() =>
            {
                cartdb.Delete(cartitem);
                await cartdb.CommitAsync();
                TempData["StatusItem"] = "Your item has been deleted!";
            });

            return(RedirectToPage("./Index"));
        }
        public async Task <ActionResult <Cart> > DeleteCart(long id, long iduser)
        {
            var result = await _cartService.Delete(id, iduser);

            if (!result)
            {
                return(BadRequest());
            }

            return(Ok(new { status = result }));
        }
示例#3
0
 public static void Delete(int[] ids, int userId)
 {
     if (userId > 0)
     {
         dal.Delete(ids, userId);
     }
     else
     {
         CartHelper.DeleteCart(string.Join(",", ids));
     }
 }
        /// <summary>
        /// Deletes a flummery from the cart
        /// </summary>
        /// <param name="productId">
        /// int: the product ID of the item to be deleted from the cart
        /// </param>
        /// <returns>
        /// Task<IActionResult>: a View directing back to the cart
        /// </returns>
        public async Task <IActionResult> OnPost(int productId)
        {
            var currentUser = await _signInManager.UserManager.GetUserAsync(User);

            var cart = await _cart.GetUserCart(currentUser.Id);

            if (cart.CartItems.Count <= 1)
            {
                await _cart.Delete(currentUser.Id);
            }
            await _cartItem.Delete(cart.Id, productId);

            return(RedirectToPage("/Cart/View"));
        }
示例#5
0
        // GET: Cart/Delete/5
        public ActionResult Delete(int?id)
        {
            if (Session["Customer_id"] != null)
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                Session["Cart"] = Cart.Delete((Session["Customer_id"]).ToString(), id);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Login", "MyAccount"));
            }
        }
 public void Delete(int CartID)
 {
     icart.Delete(CartID);
 }
        /// <summary>
        /// Send a checkout request with the provided information to AuthorizeNet
        /// </summary>
        /// <returns>Redirect to Checkout Success page if transation successful, show ModelState errors on form if not</returns>
        public async Task <IActionResult> OnPost()
        {
            #region AddressBuilding
            var currentUser = await _userManager.GetUserAsync(User);

            customerAddressType billingAddress = new customerAddressType
            {
                address   = Input.BillingAddress,
                firstName = Input.FirstName,
                lastName  = Input.LastName,
                email     = currentUser.Email,
                state     = Input.BillingState,
                zip       = Input.BillingZip,
                city      = Input.BillingCity,
            };
            customerAddressType shippingAddress = new customerAddressType();
            if (Input.SameBillingAndShipping)
            {
                shippingAddress = billingAddress;
            }
            else
            {
                shippingAddress.address   = Input.ShippingAddress;
                shippingAddress.firstName = Input.FirstName;
                shippingAddress.lastName  = Input.LastName;
                shippingAddress.email     = currentUser.Email;
                shippingAddress.state     = Input.ShippingState;
                shippingAddress.zip       = Input.ShippingZip;
                shippingAddress.city      = Input.ShippingCity;
            }
            #endregion
            if (ModelState.IsValid)
            {
                var cart = await _cart.GetUserCart(currentUser.Id);

                if (cart != null && cart.CartItems != null)
                {
                    creditCardType card = new creditCardType()
                    {
                        cardNumber     = Input.CardNumber,
                        expirationDate = "1220",
                        cardCode       = "555"
                    };

                    TransactionResponse result = _payment.Run(card, billingAddress, cart.CartItems);
                    if (result.Successful)
                    {
                        decimal         total     = 0;
                        List <CartItem> cartItems = new List <CartItem>();
                        foreach (var item in cart.CartItems)
                        {
                            cartItems.Add(item);
                            total += item.Qty * item.Product.Price;
                        }

                        OrderCart order = new OrderCart()
                        {
                            CartId          = cart.Id,
                            UserId          = currentUser.Id,
                            FirstName       = billingAddress.firstName,
                            LastName        = billingAddress.lastName,
                            Date            = DateTime.Now.ToString(),
                            BillingAddress  = billingAddress.address,
                            BillingCity     = billingAddress.city,
                            BillingState    = billingAddress.state,
                            BillingZip      = billingAddress.zip,
                            ShippingAddress = shippingAddress.address,
                            ShippingCity    = shippingAddress.city,
                            ShippingState   = shippingAddress.state,
                            ShippingZip     = shippingAddress.zip
                        };
                        await _order.Create(order);

                        order.CartItems = new List <OrderCartItem>();
                        foreach (var item in cartItems)
                        {
                            OrderCartItem orderItem = new OrderCartItem()
                            {
                                OrderCartId = cart.Id,
                                ProductId   = item.ProductId,
                                Qty         = item.Qty
                            };
                            order.CartItems.Add(orderItem);
                            await _orderItem.Create(orderItem);

                            await _cartItem.Delete(item.CartId, item.ProductId);
                        }

                        await _cart.Delete(currentUser.Id);

                        await BuildCheckoutEmail(currentUser.Email, $"{order.FirstName} {order.LastName}", cartItems, $"{shippingAddress.address} {shippingAddress.city}, {shippingAddress.state} {shippingAddress.zip}", total);

                        if (Input.SaveBillingAddress)
                        {
                            currentUser.Address = Input.BillingAddress;
                            currentUser.City    = Input.BillingCity;
                            currentUser.State   = Input.BillingState;
                            currentUser.Zip     = Input.BillingZip;
                            if (Input.BillingOptionalAddition != null || Input.BillingOptionalAddition != "")
                            {
                                currentUser.OptionalAddress = Input.BillingOptionalAddition;
                            }
                            await _userManager.UpdateAsync(currentUser);
                        }

                        return(RedirectToPage("/Checkout/Success", new { response = result.Response, cartId = cart.Id }));
                    }
                    else
                    {
                        ModelState.AddModelError("", result.Response);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Something went wrong! We couldn't find anything in your cart.");
                }
            }
            else
            {
                ModelState.AddModelError("", "Invalid input. Please try again.");
            }
            return(Page());
        }
示例#8
0
 /// <summary>
 /// 删除对应数据
 /// </summary>
 /// <param name="profileId"></param>
 /// <returns></returns>
 public int Delete(object profileId)
 {
     return(dal.Delete(profileId));
 }
示例#9
0
文件: CartManage.cs 项目: braveHUI/-
 public static void Delete(int id)
 {
     cartss.Delete(id);
 }