public IActionResult CreatePhone()
        {
            ManagerProductViewModel viewModel = new ManagerProductViewModel();

            viewModel.SubDepartments = _DepartmentData.GetAllSubDepartments();
            return(View(viewModel));
        }
        public IActionResult Index(ManagerProductViewModel vm)
        {
            if (vm.EventCommand == "list")
            {
                vm.AllProductsCount           = _ProductData.GetAll().Count();
                vm.IsListAreaVisible          = true;
                vm.IsSearchAreaVisible        = true;
                vm.IsAddPhoneFormAreaVisible  = false;
                vm.IsAddLaptopFormAreaVisible = false;
                vm.Products = _ProductData.GetPorductsofNum(vm.SkipDisplayList, vm.TakeDisplayList);
            }
            else if (vm.EventCommand == "search")
            {
                vm.IsListAreaVisible          = true;
                vm.IsSearchAreaVisible        = true;
                vm.IsAddPhoneFormAreaVisible  = false;
                vm.IsAddLaptopFormAreaVisible = false;
                vm.Products         = _ProductData.SearchByTitle(vm.ProductSearchName);
                vm.AllProductsCount = vm.Products.Count();
            }
            else if (vm.EventCommand == "addPhone")
            {
                vm.IsListAreaVisible         = false;
                vm.IsSearchAreaVisible       = false;
                vm.IsAddPhoneFormAreaVisible = true;
            }
            else if (vm.EventCommand == "addLaptop")
            {
                vm.IsListAreaVisible          = false;
                vm.IsSearchAreaVisible        = false;
                vm.IsAddPhoneFormAreaVisible  = false;
                vm.IsAddLaptopFormAreaVisible = true;

                vm.Products = _ProductData.GetAll();
            }

            else if (vm.EventCommand.Contains("editPhone"))
            {
                string productID = vm.EventCommand.Replace("editPhone/", "");
                vm.Phone                       = (Phone)_ProductData.FindProductById(int.Parse(productID));
                vm.IsListAreaVisible           = false;
                vm.IsSearchAreaVisible         = false;
                vm.IsAddPhoneFormAreaVisible   = false;
                vm.IsEditLaptopFormAreaVisible = false;
                vm.IsEditPhoneFormAreaVisible  = true;
            }
            else if (vm.EventCommand.Contains("editLaptop"))
            {
                string productID = vm.EventCommand.Replace("editLaptop/", "");
                vm.Laptop                      = (Laptop)_ProductData.FindProductById(int.Parse(productID));
                vm.IsListAreaVisible           = false;
                vm.IsSearchAreaVisible         = false;
                vm.IsAddPhoneFormAreaVisible   = false;
                vm.IsAddLaptopFormAreaVisible  = false;
                vm.IsEditLaptopFormAreaVisible = true;
            }

            vm.SubDepartments = _DepartmentData.GetAllSubDepartments();
            return(View(vm));
        }
 public IActionResult EditQty(ManagerProductViewModel viewModel)
 {
     if (viewModel.Product.Quantity >= 0)
     {
         _ProductData.EditQty(viewModel.Product);
     }
     return(Json(new { qty = viewModel.Product.Quantity, message = "success" }));
 }
        public IActionResult CreatePhone(ManagerProductViewModel viewModel)
        {
            viewModel.Phone.SubDepartment = _DepartmentData.GetSubDepartmentById(viewModel.Phone.SubDepartmentId);
            if (ModelState.IsValid)
            {
                _ProductData.AddNewProduct(viewModel.Phone);
                return(RedirectToAction("Index"));
            }
            ManagerProductViewModel newviewModel = new ManagerProductViewModel();

            newviewModel.SubDepartments = _DepartmentData.GetAllSubDepartments();
            return(View(newviewModel));
        }
Exemplo n.º 5
0
        public IActionResult EditProduct(int id, ManagerProductViewModel product)
        {
            var item = shopItemService.Get(id);

            if (ModelState.IsValid)
            {
                item.Name        = product.Name;
                item.Description = product.Description;
                item.Type        = product.Type;
                item.Price       = product.Price;
                item.Quantity    = product.Quantity;


                shopItemService.Edit(item);

                return(RedirectToAction("Product", "Home", new { id = item.Id }));
            }
            return(View(item.ToModel()));
        }
Exemplo n.º 6
0
        public IActionResult AddProduct(ManagerProductViewModel product)
        {
            if (ModelState.IsValid)
            {
                ShopItemModel item = new ShopItemModel()
                {
                    Name        = product.Name,
                    Description = product.Description,
                    Type        = product.Type,
                    Price       = product.Price,
                    Quantity    = product.Quantity,
                    DateCreated = DateTime.Now
                };

                shopItemService.Add(item.ToDomain());

                return(RedirectToAction("Index", "Manager"));
            }
            return(View());
        }
        public async Task <IActionResult> CreateLaptop(ManagerProductViewModel viewModel)
        {
            viewModel.Laptop.SubDepartment = _DepartmentData.GetSubDepartmentById(viewModel.Laptop.SubDepartmentId);
            var usersfiles = HttpContext.Request.Form.Files;

            if (ModelState.IsValid)
            {
                _ProductData.AddNewProduct(viewModel.Laptop);

                foreach (var file in usersfiles)
                {
                    // TO DO if without "upload" create one
                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    //Make sure File is Jpg
                    if (fileName.EndsWith(".jpg") || fileName.EndsWith(".png") || fileName.EndsWith(".gif"))
                    {
                        //Save Files To WWWRoot/UpLoads Folder
                        var filePath = _env.ContentRootPath + "\\wwwroot\\" + fileName;
                        await file.CopyToAsync(new FileStream(Path.Combine(Path.Combine(_env.WebRootPath, "uploads"), file.FileName + viewModel.Laptop.ProductId), FileMode.Create));

                        //Save Images to DataBase
                        byte[]       m_Bytes  = ReadToEnd(file.OpenReadStream());
                        ProductImage oneImage = new ProductImage {
                            Content = m_Bytes, FileName = fileName, FileType = FileType.Photo, ProductId = viewModel.Laptop.ProductId, ContentType = file.ContentType
                        };
                        _ProductData.SaveProductImages(oneImage);
                    }
                }

                return(RedirectToAction("Index"));
            }

            ManagerProductViewModel newviewModel = new ManagerProductViewModel();

            newviewModel.SubDepartments = _DepartmentData.GetAllSubDepartments();
            return(View(newviewModel));
        }
 public IActionResult EditPhone(ManagerProductViewModel viewModel)
 {
     _ProductData.Edit(viewModel.Phone);
     return(RedirectToAction("Index"));
 }
        public IActionResult Delete(ManagerProductViewModel viewModel)
        {
            _ProductData.DeleteProduct(viewModel.Product.ProductId);

            return(RedirectToAction("Index"));
        }