public IActionResult DeleteCart(Cart cart)
 {
     try
     {
         _cartServices.DeleteCart(cart);
         return(CreatedAtAction("DeleteCart", cart));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Esempio n. 2
0
        public Customer CustomerValidation()
        {
            string filepath = "../lacrosseDB/DBFiles/Customer.txt";

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.File(filepath, rollingInterval: RollingInterval.Day)
                         .CreateLogger();

            string   email;
            Customer cust = new Customer();

            Console.WriteLine("Enter email");
            email = Console.ReadLine();
            try
            {
                cust = customerServices.GetCustomerByEmail(email);
                if (cust.email != email)
                {
                    throw new System.ArgumentException();
                }
                else
                {
                    customer = cust;
                    Log.Information($"{cust.email} has signed in");
                    CustMenu custMenu = new CustMenu(customer, context);
                    try
                    {
                        cartServices.DeleteCart(cartServices.GetCartByCustId(customer.Id));
                    }
                    catch (InvalidOperationException) { }
                    finally
                    {
                        Cart newCart = new Cart();
                        newCart.custId = customer.Id;
                        cartServices.AddCart(newCart);
                        custMenu.Start();
                    }
                }
            }
            catch (ArgumentException)
            {
                Log.Information($"Customer {cust.email} tried and failed to login.");
                ValidInvalidServices.InvalidInput();
            }
            catch (InvalidOperationException)
            {
                Log.Information($"Customer tried to sign into an account the DNE.");
                ValidInvalidServices.InvalidInput();
            }
            return(cust);
        }
        public JsonResult DeleteCart(int productId)
        {
            int id = 0;

            try
            {
                //removing the item from cart
                CartServices service = new CartServices();
                User         user    = (User)(Session[SessionConstants.SESSION_CONTEXT_INSTANCE]);
                id = service.DeleteCart(productId, user.UserId);
                return(Json(new { Status = true, Message = "Delete Success" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Status = false, Message = "Error Occured" }, JsonRequestBehavior.AllowGet));
            }
        }