예제 #1
0
        public async Task <IActionResult> CreateProduct(CreateProductView model)
        {
            Product product = new Product();

            if (model.Image != null)
            {
                var uniqueFileName = GetUniqueFileName(model.Image.FileName);
                var uploads        = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                var filePath       = Path.Combine(uploads, uniqueFileName);
                model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
                product.Name  = model.Name;
                product.Note  = model.Note;
                product.Price = model.Price;
                product.Genre = model.Genre;
                product.Image = uniqueFileName;
            }
            else
            {
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                _context.Product.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Product)));
            }
            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> EditProduct(int id)
        {
            if (HttpContext.Session.GetInt32("Privileze") != 1)
            {
                return(NotFound());
            }
            if (id == 0)
            {
                return(NotFound());
            }

            var product = await _context.Product.FindAsync(id);

            if (product == null)
            {
                return(NotFound());
            }
            CreateProductView model = new CreateProductView()
            {
                Id    = product.Id,
                Name  = product.Name,
                Genre = product.Genre,
                Price = product.Price,
                Note  = product.Note
            };

            return(View(model));
        }
예제 #3
0
        private void FunctionSwitcher(string SelectedFunctionName)
        {
            UserControl usc;

            switch (SelectedFunctionName)
            {
            case "Create":
                usc = new CreateProductView();
                break;

            case "Update":
                usc             = new UpdateProductView();
                usc.DataContext = new ProductViewModel {
                    SelectedProductId = this.SelectedProductId
                };
                break;

            case "Delete":
                DeleteProduct();
                usc = new ProductsView();
                break;

            case "Category":
                usc = new CategoryView();
                break;

            default:
                usc = new ProductsView();
                break;
            }
            ;
            Session.Instance.SetNextView(usc);
        }
예제 #4
0
        public void AddProduct(CreateProductView formData)
        {
            var product = Mapper.Map <Product>(formData);

            product.CreatedAt = DateTime.Now;
            product.UpdatedAt = DateTime.Now;

            _db.Products.Add(product);
            _db.SaveChanges();
        }
예제 #5
0
        public ActionResult Create(CreateProductView formData)
        {
            try
            {
                _productService.AddProduct(formData);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #6
0
        public IActionResult Create(CreateProductView product)
        {
            if (ModelState.IsValid)
            {
                if (productRepository.CreateProduct(product) > 0)
                {
                    return(RedirectToAction("Index", "Product"));
                }

                ModelState.AddModelError("", "Tên sản phẩm đã tồn tại");
            }
            return(View(product));
        }
예제 #7
0
        public IActionResult Create(CreateProductView productView)
        {
            if (ModelState.IsValid)
            {
                if (productRepository.CreateProduct(productView) > 0)
                {
                    return(RedirectToAction("Index", "Product"));
                }

                ModelState.AddModelError("", TextErrorToView.WrongMess);
            }
            return(View());
        }
 public IActionResult Create(CreateProductView productView)
 {
     if (ModelState.IsValid)
     {
         if (_productService.CreateProduct(productView) > 0)
         {
             return(RedirectToAction("Index", "Product"));
         }
         else
         {
             ModelState.AddModelError("", "something wrong");
         }
     }
     return(View());
 }
예제 #9
0
        public async Task <IActionResult> EditProduct(int id, CreateProductView model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            Product product = new Product();

            if (model.Image != null)
            {
                var uniqueFileName = GetUniqueFileName(model.Image.FileName);
                var uploads        = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                var filePath       = Path.Combine(uploads, uniqueFileName);
                model.Image.CopyTo(new FileStream(filePath, FileMode.Create));

                product.Image = uniqueFileName;
            }
            product.Id    = model.Id;
            product.Name  = model.Name;
            product.Note  = model.Note;
            product.Price = model.Price;
            product.Genre = model.Genre;
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Product.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
예제 #10
0
        public int CreateProduct(CreateProductView productView)
        {
            Product product = new Product()
            {
                Name         = productView.Name,
                PricePerUnit = productView.Price,
                CreateAt     = productView.CreateAt,
                CreateBy     = productView.CreateBy,
                CategoryId   = productView.CategoryId
            };

            if (productView.IformfilePath != null)
            {
                product.ImagePath = UploadedFile(productView.IformfilePath);
            }

            context.Products.Add(product);
            return(context.SaveChanges());
        }
        public IActionResult Create(CreateProductView productView)
        {
            if (ModelState.IsValid)
            {
                int result = productRepository.CreateProduct(productView);
                if (result == -1)
                {
                    ModelState.AddModelError("", "Tên Sản Phẩm Đả Tồn Tại");
                    return(View(productView));
                }

                if (result > 0)
                {
                    return(RedirectToAction("Index", "Product"));
                }

                ModelState.AddModelError("", TextErrorToView.WrongMess);
            }
            return(View());
        }
예제 #12
0
 public int CreateProduct(CreateProductView productView)
 {
     foreach (var item in _context.Products)
     {
         if (item.Name != productView.Name)
         {
             Product product = new Product()
             {
                 Name       = productView.Name,
                 Price      = productView.Price,
                 CreateAt   = productView.CreateAt,
                 CategoryId = productView.CategoryId,
                 AvataPath  = UploadedFile(productView.Avata)
             };
             _context.Add(product);
             return(_context.SaveChanges());
         }
     }
     return(0);
 }
예제 #13
0
        public IActionResult CreateProduct(CreateProductView model)
        {
            if (HttpContext.Session.GetString("CurrentUserFirstName") == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.Categories = _context.ProductCategories;

            if (ModelState.IsValid)
            {
                Product newProduct = new Product {
                    Name            = model.Name,
                    Description     = model.Description,
                    CreatedByUserId = (int)HttpContext.Session.GetInt32("CurrentUserId")
                };

                _context.Products.Add(newProduct);
                _context.SaveChanges();
                newProduct = _context.Products.Last();

                foreach (int catId in model.CategoryId)
                {
                    ProductsProductCategories newPPC = new ProductsProductCategories {
                        ProductCategoryId = catId,
                        ProductId         = newProduct.id
                    };
                    _context.ProductsProductCategories.Add(newPPC);
                }

                _context.SaveChanges();


                return(RedirectToAction("Dashboard", "ShoppingList"));
            }
            else
            {
                return(View(model));
            }
        }
예제 #14
0
        static void Main(string[] args)
        {
            var mainMenu = new MainView();

            var run = true;

            while (run)
            {
                //MAIN MENU
                string userInput = mainMenu.MainMenu();
                char   input     = Convert.ToChar(userInput);

                switch (input)
                {
                case '0':
                    run = false;
                    break;

                case '1':                         //"Add Customer"
                    var newCreateCustomer = new NewCustomerView();

                    var customerFirstName = newCreateCustomer.GetFirstName();
                    var customerLastName  = newCreateCustomer.GetLastName();
                    var customerStreet    = newCreateCustomer.GetStreet();
                    var customerCity      = newCreateCustomer.GetCity();
                    var customerState     = newCreateCustomer.GetState();
                    var customerZip       = newCreateCustomer.GetZip();
                    var customerPhone     = newCreateCustomer.GetPhone();
                    var customerEmail     = newCreateCustomer.GetEmail();

                    var customerInfo = new InsertCustomerQuery();
                    customerInfo.InsertCustomer(customerFirstName, customerLastName, customerStreet, customerCity, customerState, customerZip, customerPhone, customerEmail);

                    break;

                case '2':                         //"Select Customer"

                    var viewAllCustomers = new AllCustomersView();
                    _selectedCustomer = viewAllCustomers.SelectActiveCustomer();

                    var activeCustomerQuery = new SelectActiveCustomerQuery();
                    var activeCustomers     = activeCustomerQuery.SelectActiveCustomer();

                    // BUY AND SELL SUB MENU
                    var customerSubMenu = new CustomerSubMenuView();
                    var userOption      = customerSubMenu.CustomerSubMenu(_selectedCustomer);
                    var userRole        = Convert.ToChar(userOption);

                    switch (userRole)
                    {
                    case '1':                                     //Buyer Menu
                        var buyerMenu = new BuyerMenuView();
                        buyerMenu.BuyerMenu(_selectedCustomer);

                        break;

                    case '2':                                     //Seller Menu
                        var    sellerMenu  = new SellerMenuView();
                        string sellerInput = sellerMenu.SellerMenu(_selectedCustomer);
                        var    sellerChar  = Convert.ToChar(sellerInput);

                        switch (sellerChar)
                        {
                        case '1':                                                //Add Product
                            var addProductView  = new CreateProductView();
                            var customerId      = (_selectedCustomer.CustomerId);
                            var productTitle    = addProductView.GetProdcutTitle(_selectedCustomer);
                            var productPrice    = addProductView.GetProdcutPrice(_selectedCustomer);
                            var productQuantity = addProductView.GetProdcutQuantity(_selectedCustomer);
                            var addProduct      = new InsertProductQuery();
                            var newProduct      = addProduct.InsertProduct(customerId, productTitle, productPrice, productQuantity);
                            break;

                        case '2':                                                 //Edit Product
                            var viewAllProductsForSeller = new AllProductsForSellerView();
                            var selectedProduct          = viewAllProductsForSeller.SelectProduct(_selectedCustomer);
                            var updateProductView        = new UpdateProductView();

                            var updateProduct   = updateProductView.UpdateProductMenu(selectedProduct, _selectedCustomer);
                            var productSelected = Convert.ToChar(updateProduct);

                            switch (productSelected)
                            {
                            case '1':
                                var title = updateProductView.UpdateTitle();
                                var updateProductTitleQuery = new UpdateProductQueries();
                                var executeUpdateTitle      = updateProductTitleQuery.UpdateProductTitle(selectedProduct.ProductId, title);
                                break;

                            case '2':
                                var price = updateProductView.UpdatePrice();
                                var updateProductPriceQuery = new UpdateProductQueries();
                                var executeUpdatePrice      = updateProductPriceQuery.UpdateProductPrice(selectedProduct.ProductId, price);
                                break;

                            case '3':
                                var quantity = updateProductView.UpdateQuantity();
                                var updateProductQuantityQuery = new UpdateProductQueries();
                                var executeUpdateQuantity      = updateProductQuantityQuery.UpdateProductQuantity(selectedProduct.ProductId, quantity);
                                break;

                            default:                                                             //Default for Update Product Menu
                                break;
                            }
                            break;

                        case '3':                                                 //Delete Product
                            viewAllProductsForSeller = new AllProductsForSellerView();
                            var productToDelete      = viewAllProductsForSeller.SelectProduct(_selectedCustomer);
                            var deleteProduct        = new DeleteProductQuery();
                            var executeDeleteProduct = deleteProduct.DeleteProduct(productToDelete.ProductId);

                            break;

                        case '4':             //Revenue Report
                            var revenueReportView = new RevenueReportView();
                            revenueReportView.RunRevenueReport(_selectedCustomer);
                            break;

                        default:                                                 //Default for Seller Menu
                            break;
                        }

                        break;

                    default:                                     //Default for BUY/SELL Menu
                        break;
                    }

                    break;

                default:                         //Default for Main Menu
                    break;
                }
            }
        }