public GenericResponse RemoveProduct(RemoveProduct request, string userId)
        {
            try
            {
                Product product = db.Products.Where(p => p.Id == request.productId).FirstOrDefault();

                product.IsDeleted = true;

                db.SaveChanges();


                return(new GenericResponse());
            }
            catch (Exception ex)
            {
                ApiLog log = new ApiLog();

                log.Request    = request.ToString();
                log.MethodName = "RemoveProduct";
                log.Exception  = ex.ToString();
                log.UserId     = userId;

                db.ApiLog.Add(log);
                db.SaveChanges();

                return(new GenericResponse(ex));
            }
        }
Beispiel #2
0
 public Task <Unit> Handle(RemoveProduct command, CancellationToken cancellationToken)
 {
     return(cartRepository.GetAndUpdate(
                command.CartId,
                cart => cart.RemoveProduct(command.ProductItem),
                cancellationToken));
 }
        public async Task <ActionResult <RemoveProductDTO> > DeleteProduct(string id, RemoveProduct removeProduct)
        {
            var productToRemove = await _context.Products.FindAsync(id);

            RemoveProduct removeProductModel = removeProduct;

            if (productToRemove == null)
            {
                return(BadRequest(this.GetError(Error.PRODUCT_NOT_FOUND)));
            }
            if (!this.ValidTokenAdmin(removeProductModel.AccessToken))
            {
                return(BadRequest(this.GetError(Error.INVALID_TOKEN)));
            }

            productToRemove.Status = "INACTIVE";

            _context.Entry(productToRemove).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            RemoveProductDTO removeProductDTO = new RemoveProductDTO(productToRemove);

            return(removeProductDTO);
        }
        public GenericResponse RemoveProduct(RemoveProduct request)

        {
            string userId = ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst(ClaimTypes.NameIdentifier).Value.ToString();

            return(repository.RemoveProduct(request, userId));
        }
Beispiel #5
0
 //Remove product
 private bool Validate(RemoveProduct command)
 {
     if (!cartState.Lines.Any(line => line.ProductName == command.ProductName))
     {
         return(Reject($"Can't remove product '{command.ProductName}' because it's not in the cart"));
     }
     return(Accept());
 }
        public async Task Handle(RemoveProduct command)
        {
            var product = await _productRepository.GetProduct(command.Id);

            _productRepository.RemoveProduct(product);

            await _unitOfWork.Commit();
        }
Beispiel #7
0
        public bool DeleteProduct(Customer activeCustomer)
        {
            Console.Clear();
            Console.WriteLine("1: Remove Product");
            Console.WriteLine("2: Return to Main Menu");
            var productSubSelection = Console.ReadKey();
            var remove = true;

            while (remove)
            {
                switch (productSubSelection.KeyChar)
                {
                case '0':
                    remove = false;
                    break;

                case '1':
                    Console.Clear();
                    Console.WriteLine("Type a product id and press enter...");
                    // Generate Product Menu //
                    var customerProducts = new GetProductList();
                    var ProductData      = customerProducts.GetProducts(activeCustomer.CustomerID);

                    foreach (var product in ProductData)
                    {
                        Console.WriteLine($"{product.ProductID}. {product.Name}: {product.Price}");
                    }
                    Console.WriteLine("\nPress [0] to return to the main menu");

                    // Read Input and Remove Product by ID //
                    var selection     = Console.ReadLine();
                    var productDelete = new RemoveProduct().DeleteProduct(int.Parse(selection));
                    if (int.Parse(selection) == 0)
                    {
                        remove = false;
                    }
                    else if (productDelete)
                    {
                        Console.WriteLine("Product deleted press enter to relaod list");
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.WriteLine("Product not deleted or does not exist");
                    }
                    //Console.ReadKey();
                    break;

                case '2':
                    remove = false;
                    break;
                }
            }
            return(true);
        }
        public void ShouldRemoveProduct()
        {
            var createdProduct = CreateNewProduct();

            CommitDatabaseChanges.Commit();
            RemoveProduct removeProdct = new RemoveProduct();

            removeProdct.InputArgument = createdProduct;
            removeProdct.Execute();
            CommitDatabaseChanges.Commit();
            Assert.IsTrue(removeProdct.OutputArgument);
        }
Beispiel #9
0
        public async Task <Result> Handle(RemoveProduct command, CancellationToken cancellationToken)
        {
            var product = await _repository.FindAsync(command.ProductId, cancellationToken);

            if (!product.HasValue)
            {
                return(Fail("Product not found!"));
            }

            _repository.Remove(product.Value);
            await _uow.SaveChangesAsync(cancellationToken);

            return(Ok());
        }
        public void CleanChanges()
        {
            GetProduct getProduct = new GetProduct();

            getProduct.InputArgument = p => p.Code.Contains("product code");
            getProduct.Execute();
            if (getProduct.OutputArgument != null)
            {
                foreach (var item in getProduct.OutputArgument)
                {
                    RemoveProduct removeProduct = new RemoveProduct();
                    removeProduct.InputArgument = item;
                    removeProduct.Execute();
                }
            }
            CommitDatabaseChanges.Commit();
        }
Beispiel #11
0
 public AdminController(RequestUserData requestUserData, RequestAllUsers requestAllUsers, RequestAllTransactions requestAllTransactions,
                        RequestTerminalWithProduct requestTerminalWithProduct, RequestUserWithUserId requestUserWithUserId, EditEmployeeWithId editEmployeeWithId,
                        RequestAllProducts requestAllProducts, RequestProductWithProductId requestProductWithProductId, EditProductWithId editProductWithId,
                        RegisterNewProduct registerNewProduct, RegisterNewTerminal registerNewTerminal, RemoveTerminal removeTerminal, RemoveProduct removeProduct,
                        RegisterProductToTerminal registerProductToTerminal, RequestAllTransactionsWithType requestAllTransactionsWithType, EditTransactionTypeWithId editTransactionTypeWithId)
 {
     _requestUserData             = requestUserData;
     _requestAllUsers             = requestAllUsers;
     _requestAllTransactions      = requestAllTransactions;
     _requestTerminalWithProduct  = requestTerminalWithProduct;
     _requestUserWithUserId       = requestUserWithUserId;
     _editEmployeeWithId          = editEmployeeWithId;
     _requestAllProducts          = requestAllProducts;
     _requestProductWithProductId = requestProductWithProductId;
     _editProductWithId           = editProductWithId;
     _registerNewProduct          = registerNewProduct;
     _registerNewTerminal         = registerNewTerminal;
     _removeTerminal                 = removeTerminal;
     _removeProduct                  = removeProduct;
     _registerProductToTerminal      = registerProductToTerminal;
     _requestAllTransactionsWithType = requestAllTransactionsWithType;
     _editTransactionTypeWithId      = editTransactionTypeWithId;
 }
Beispiel #12
0
        private void removeP_Click_1(object sender, RoutedEventArgs e)
        {
            Page p = new RemoveProduct();

            NavigationService.Navigate(p);
        }
 public Task <string> Handle(RemoveProduct request, CancellationToken cancellationToken)
 {
     return(Task.FromResult("Product removed"));
 }
Beispiel #14
0
        private void Handle(RemoveProduct command)
        {
            var domainEvent = new ProductRemoved(command.ProductName);

            Persist(domainEvent, Apply);
        }
        static void Main(string[] args)
        {
            var customer = new CustomerList();
            var run      = true;

            while (run)



            {
                var userInput = MainMenu(customer.CustomerId);
                switch (int.Parse(userInput))
                {
                case 1:
                    Console.Clear();



                    Console.WriteLine("You've chosen to create a new customer account.");

                    Console.WriteLine("Enter your first name");
                    var firstName = Console.ReadLine();

                    Console.WriteLine("Enter your last name");
                    var lastName = Console.ReadLine();

                    Console.WriteLine("Enter your street address");
                    var address = Console.ReadLine();

                    Console.WriteLine("Enter your city");
                    var city = Console.ReadLine();

                    Console.WriteLine("Enter your state");
                    var state = Console.ReadLine();

                    Console.WriteLine("Enter your postal code");
                    var postalCode = Console.ReadLine();

                    Console.WriteLine("Finally, enter your phone number");
                    var phone = Console.ReadLine();


                    var newCustomerInfo = new CreateCustomerAccount();
                    var newCustomer     = newCustomerInfo.AddNewCustomerInfo(firstName, lastName, address, city, state, postalCode, phone);

                    if (newCustomer)
                    {
                        Console.WriteLine("You added a customer!");
                    }
                    System.Threading.Thread.Sleep(1000);
                    break;

                case 2:
                    Console.Clear();
                    var counter             = 0;
                    var customerList        = new SelectCustomer();
                    var listOfCustomerNames = customerList.GetCustomerName();
                    Console.WriteLine("Which customer will be active?");
                    foreach (var list in listOfCustomerNames)
                    {
                        counter++;
                        Console.WriteLine($"{counter} {list.FirstName} {list.LastName}");
                    }

                    var selectedCustomer      = Console.ReadLine();
                    var selectedCustomerIndex = int.Parse(selectedCustomer.ToString());
                    customer = listOfCustomerNames[selectedCustomerIndex - 1];
                    Console.WriteLine($"the selected customer is {customer.FirstName} {customer.LastName}");
                    System.Threading.Thread.Sleep(1000);
                    break;

                case 3:
                    Console.Clear();

                    Console.WriteLine("What kind of Credit Card are you adding?");
                    var pmtType = Console.ReadLine();

                    Console.WriteLine("What is the account number?");
                    var acctNumber    = Console.ReadLine();
                    var acctNumberInt = long.Parse(acctNumber.ToString());

                    var customerId = customer.CustomerId;

                    var payment = new AddPayment();

                    payment.AddPaymentType(pmtType, customerId, acctNumberInt);

                    Console.WriteLine($"You have added {pmtType} {acctNumber} to {customer.FirstName} {customer.LastName}");
                    System.Threading.Thread.Sleep(1000);

                    break;

                case 4:
                    Console.Clear();
                    //Add product to sell
                    var productAdder = new ProductAdder();
                    Console.WriteLine("Enter the Product Name: ");
                    var productName = Console.ReadLine();
                    Console.WriteLine("Enter the Product Description: ");
                    var productDescription = Console.ReadLine();
                    Console.WriteLine("Enter the Product Price: ");
                    var productPrice = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("Enter the Product Quantity: ");
                    var quantity  = Convert.ToInt32(Console.ReadLine());
                    var customers = productAdder.GetAllCustomers();

                    var counter4 = 0;
                    Console.WriteLine("Please select the customer whose product you are adding:");
                    foreach (var person in customers)
                    {
                        counter4++;
                        Console.WriteLine($"{counter4}. {person.FirstName} {person.LastName}");
                    }

                    var customerToAddProduct = int.Parse(Console.ReadLine());

                    var customerIdToAdd = customers[customerToAddProduct - 1];
                    var newProduct      = productAdder.AddNewProduct(productName, productDescription, productPrice, quantity, customerIdToAdd.CustomerId);
                    if (newProduct)
                    {
                        Console.WriteLine($"You added {productName} to {customerIdToAdd.FirstName} {customerIdToAdd.LastName}!");
                    }
                    System.Threading.Thread.Sleep(1000);
                    break;

                case 5:
                    Console.Clear();
                    //Add product to shopping cart
                    var productQuery  = new ProductQuery();
                    var allProducts   = productQuery.GetAllProducts();
                    var addProduct    = new AddProduct();
                    var orderModifier = new OrderModifier();

                    var order          = 0;
                    var addingProducts = true;
                    while (addingProducts)
                    {
                        Console.WriteLine("All Products");
                        var counter2 = 0;
                        foreach (var product in allProducts)
                        {
                            counter2++;
                            Console.WriteLine($"{counter2}. {product.ProductName}: {product.ProductPrice}");
                        }
                        counter2++;
                        Console.WriteLine($"{counter2}. Done adding products.");

                        Console.WriteLine("What product would you like to add to the order?");
                        var productToAdd = Console.ReadLine();
                        Console.WriteLine("");
                        var selectedProductIndex = int.Parse(productToAdd.ToString());
                        if (selectedProductIndex == counter2)
                        {
                            addingProducts = false;
                            break;
                        }
                        Console.WriteLine("How many would you like to add?");
                        var numberToAdd = Console.ReadLine();
                        var addedNumber = int.Parse(numberToAdd.ToString());
                        Console.WriteLine("");

                        var selectedProduct = allProducts[selectedProductIndex - 1];
                        if (order == 0)
                        {
                            order = orderModifier.CreateOrder(customer.CustomerId);
                        }
                        var addNewProduct = addProduct.AddProductToOrder(selectedProduct.ProductId, addedNumber, order);
                        if (addNewProduct)
                        {
                            Console.WriteLine($"You added {selectedProduct.ProductName} to your order!");
                        }
                        System.Threading.Thread.Sleep(1000);
                        Console.Clear();
                    }
                    break;

                case 6:
                    Console.Clear();
                    //Complete an order
                    break;

                case 7:
                    Console.Clear();
                    //Remove customer product
                    Console.WriteLine("Please choose product to delete:");

                    var removeCustomerProduct = new RemoveProduct();
                    removeCustomerProduct.RemoveCustomerProduct(customer);

                    break;

                case 8:
                    Console.Clear();
                    //Update product information
                    var getAllProducts   = new ProductQuery();
                    var productsToUpdate = getAllProducts.GetCustomerProducts(customer.CustomerId);
                    Console.WriteLine("All Products");
                    var counter3 = 0;
                    foreach (var product in productsToUpdate)
                    {
                        counter3++;
                        Console.WriteLine($"{counter3}. {product.ProductName}: {product.ProductPrice}");
                    }

                    Console.WriteLine("What product would you like to update?");
                    var productToUpdate = Console.ReadLine();
                    Console.WriteLine("");
                    var updateProductIndex = int.Parse(productToUpdate.ToString());
                    var updateThisProduct  = productsToUpdate[updateProductIndex - 1];
                    Console.Clear();
                    var productModifier = new AddProduct();
                    var updateProduct   = productModifier.UpdateProduct(updateThisProduct);
                    if (updateProduct)
                    {
                        Console.WriteLine("Product updated!");
                    }


                    System.Threading.Thread.Sleep(1000);
                    break;

                case 9:
                    Console.Clear();
                    //Show stale products
                    break;

                case 10:
                    Console.Clear();
                    var revenueQuery   = new RevenueQuery();
                    var listOfRevenues = revenueQuery.GetCustomerRevenue(customer.FirstName, customer.LastName);

                    var personRevenue = from personOrder in listOfRevenues
                                        group personOrder by personOrder.OrderId into g
                                        orderby g.Key
                                        select g;

                    var revenueCounter = 0.00;

                    Console.WriteLine($"This is the revenue report for {customer.FirstName} {customer.LastName}");
                    foreach (var revenueResult in personRevenue)
                    {
                        Console.WriteLine($"\nOrder #{revenueResult.Key}\n--------------------------------------");


                        foreach (var item in revenueResult)
                        {
                            revenueCounter += item.indivItemTotal;
                            Console.WriteLine($"{item.ProductName}     {item.OrderItemQuantity}   ${item.indivItemTotal} ");
                        }
                        //Console.WriteLine()
                    }
                    Console.WriteLine($"\nTotal Revenue is ${revenueCounter}");
                    Console.ReadLine();

                    break;

                case 11:
                    Console.Clear();
                    //Show overall product popularity
                    var revenueReport = new RevenueReport();
                    revenueReport.GetTop3Revenue();
                    break;

                case 12:
                    //Leave Bangazon!
                    run = false;
                    break;
                }
            }

            string MainMenu(int customerid)
            {
                View mainMenu = new View()
                                .AddMenuOption("1. Create a customer account")
                                .AddMenuOption("2. Choose active customer")
                                .AddMenuOption("4. Add product to sell")
                                .AddMenuOption("9. Show stale products")
                                .AddMenuOption("10. Show customer revenue report")
                                .AddMenuOption("11. Show overall product popularity")
                                .AddMenuOption("12. Leave Bangazon!");

                Console.Write(mainMenu.GetFullMenu());

                if (customerid > 0)
                {
                    mainMenu = new View()
                               .AddMenuOption("1. Create a customer account")
                               .AddMenuOption("2. Choose active customer")
                               .AddMenuOption("3. Create a payment option")
                               .AddMenuOption("4. Add product to sell")
                               .AddMenuOption("5. Add product to shopping cart")
                               .AddMenuOption("6. Complete an order")
                               .AddMenuOption("7. Remove customer product")
                               .AddMenuOption("8. Update product information")
                               .AddMenuOption("9. Show stale products")
                               .AddMenuOption("10. Show customer revenue report")
                               .AddMenuOption("11. Show overall product popularity")
                               .AddMenuOption("12. Leave Bangazon!");
                    Console.Write(mainMenu.GetFullMenu());
                }

                var userOption = Console.ReadLine();

                return(userOption);
            }
        }
 public Task <string> Handle(RemoveProduct request, CancellationToken cancellationToken)
 {
     //Interact with Service, DatabaseContext, Stream or something else
     return(Task.FromResult("Product removed"));
 }