Ejemplo n.º 1
0
        // GET: Admin/Products/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var product = await _context.Products.SingleOrDefaultAsync(m => m.ProductID == id);

            if (product == null)
            {
                return(NotFound());
            }

            AdminProductViewModel vm = new AdminProductViewModel()
            {
                ProductID               = product.ProductID,
                AvailableQuantity       = Math.Round(product.AvailableQuantity, 2).ToString(),
                Description             = product.Description,
                MinimumPurchaseQuantity = Math.Round(product.MinimumPurchaseQuantity, 2).ToString(),
                Name                  = product.Name,
                Price                 = Math.Round(product.Price, 2).ToString(),
                ProductNumber         = product.ProductNumber,
                PeriodID              = product.ShippingPeriod,
                SizeID                = product.Size,
                ShortDescription      = product.ShortDescription,
                BasesUnitID           = product.BasesUnitID,
                SecondBaseUnitID      = product.SecondBaseUnit,
                SecondBasePrice       = Math.Round(product.SecondBasePrice, 2).ToString(),
                IsActive              = product.IsActive,
                BasesUnit             = new UnitHelper(_context, factory).GetUnitName(product.BasesUnitID),
                Period                = new ShippingPeriodHelper(_context).GetDescription(product.ShippingPeriod),
                SecondBaseUnit        = new UnitHelper(_context, factory).GetUnitName(product.SecondBaseUnit),
                Size                  = new SizeHelper(_context).GetName(product.Size),
                ImageUrls             = new ProductImageHelper(_context, factory).GetUrls(product.ProductID),
                ShippingPriceTypeID   = product.ShippingPriceType,
                ShippingPriceTypeName = new ShippingPriceTypeHelper(_context).GetNameByID(product.ShippingPriceType),
                SeoDescription        = product.SeoDescription,
                SeoKeywords           = product.SeoKeywords
            };

            List <UnitViewModel>           vmunits            = new UnitHelper(_context, factory).GetVmUnits();
            List <SizeViewModel>           vwsizes            = new SizeHelper(_context).GetVmSizes();
            List <ShippingPeriodViewModel> periods            = new ShippingPeriodHelper(_context).GetVmShippingPeriods();
            List <SelectItemViewModel>     catvms             = new CategoryHelper(_context).GetVmList();
            List <SelectItemViewModel>     catsubvms          = new CategorySubHelper(_context).GetVmList();
            List <SelectItemViewModel>     catdeatailvms      = new CategoryDetailHelper(_context).GetVmList();
            List <SelectItemViewModel>     shippingPriceTypes = new ShippingPriceTypeHelper(_context).GetVmList();

            ViewData["BaseUnit"]            = new SelectList(vmunits, "UnitID", "Name");
            ViewData["Size"]                = new SelectList(vwsizes, "ID", "Name");
            ViewData["SeconedUnit"]         = new SelectList(vmunits, "UnitID", "Name");
            ViewData["Periods"]             = new SelectList(periods, "ID", "Value");
            ViewData["CategoryID"]          = new SelectList(catvms, "ID", "Name");
            ViewData["CategorySubID"]       = new SelectList(catsubvms, "ID", "Name");
            ViewData["CategoryDetailID"]    = new SelectList(catdeatailvms, "ID", "Name");
            ViewData["ShippingPriceTypeID"] = new SelectList(shippingPriceTypes, "ID", "Name");

            return(View(vm));
        }
        // GET: Admin/CategoryAssignments/Create
        public IActionResult Create()
        {
            List <SelectItemViewModel> catvms        = new CategoryHelper(_context).GetVmList();
            List <SelectItemViewModel> catsubvms     = new CategorySubHelper(_context).GetVmList();
            List <SelectItemViewModel> catdeatailvms = new CategoryDetailHelper(_context).GetVmList();

            ViewData["CategoryID"]       = new SelectList(catvms, "ID", "Name");
            ViewData["CategorySubID"]    = new SelectList(catsubvms, "ID", "Name");
            ViewData["CategoryDetailID"] = new SelectList(catdeatailvms, "ID", "Name");

            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Name");
            return(View());
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,ProductID,CategoryID,CategorySubID,CategoryDetailID")] CategoryAssignment categoryAssignment)
        {
            if (id != categoryAssignment.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(categoryAssignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryAssignmentExists(categoryAssignment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            List <SelectItemViewModel> catvms        = new CategoryHelper(_context).GetVmList();
            List <SelectItemViewModel> catsubvms     = new CategorySubHelper(_context).GetVmList();
            List <SelectItemViewModel> catdeatailvms = new CategoryDetailHelper(_context).GetVmList();

            ViewData["CategoryID"]       = new SelectList(catvms, "ID", "Name");
            ViewData["CategorySubID"]    = new SelectList(catsubvms, "ID", "Name");
            ViewData["CategoryDetailID"] = new SelectList(catdeatailvms, "ID", "Name");

            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Name", categoryAssignment.ProductID);
            return(View(categoryAssignment));
        }
        public async Task <IActionResult> Create([Bind("ID,ProductID,CategoryID,CategorySubID,CategoryDetailID")] CategoryAssignment categoryAssignment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categoryAssignment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            List <SelectItemViewModel> catvms        = new CategoryHelper(_context).GetVmList();
            List <SelectItemViewModel> catsubvms     = new CategorySubHelper(_context).GetVmList();
            List <SelectItemViewModel> catdeatailvms = new CategoryDetailHelper(_context).GetVmList();

            ViewData["CategoryID"]       = new SelectList(catvms, "ID", "Name");
            ViewData["CategorySubID"]    = new SelectList(catsubvms, "ID", "Name");
            ViewData["CategoryDetailID"] = new SelectList(catdeatailvms, "ID", "Name");

            ViewData["CheckList"] = new MultiSelectList(catvms, "ID", "Name");

            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Name", categoryAssignment.ProductID);
            return(View(categoryAssignment));
        }
Ejemplo n.º 5
0
        // GET: Admin/Products/Create
        public IActionResult Create()
        {
            int actProductNumber = 0;
            var lastProd         = _context.Products.LastOrDefault();

            if (lastProd != null)
            {
                actProductNumber = lastProd.ProductNumber + 1;
            }
            else
            {
                actProductNumber = 1000;
            }
            //ViewData["MainGroupID"] =  new SelectList(_context.Catagories, "CatagoryID", "Name");


            List <UnitViewModel>           vmunits            = new UnitHelper(_context, factory).GetVmUnits();
            List <SizeViewModel>           vwsizes            = new SizeHelper(_context).GetVmSizes();
            List <ShippingPeriodViewModel> periods            = new ShippingPeriodHelper(_context).GetVmShippingPeriods();
            List <SelectItemViewModel>     catvms             = new CategoryHelper(_context).GetVmList();
            List <SelectItemViewModel>     catsubvms          = new CategorySubHelper(_context).GetVmList();
            List <SelectItemViewModel>     catdeatailvms      = new CategoryDetailHelper(_context).GetVmList();
            List <SelectItemViewModel>     shippingPriceTypes = new ShippingPriceTypeHelper(_context).GetVmList();

            ViewData["BaseUnit"]            = new SelectList(vmunits, "UnitID", "Name");
            ViewData["Size"]                = new SelectList(vwsizes, "ID", "Name");
            ViewData["SeconedUnit"]         = new SelectList(vmunits, "UnitID", "Name");
            ViewData["Periods"]             = new SelectList(periods, "ID", "Value");
            ViewData["CategoryID"]          = new SelectList(catvms, "ID", "Name");
            ViewData["CategorySubID"]       = new SelectList(catsubvms, "ID", "Name");
            ViewData["CategoryDetailID"]    = new SelectList(catdeatailvms, "ID", "Name");
            ViewData["ShippingPriceTypeID"] = new SelectList(shippingPriceTypes, "ID", "Name");

            var vm = new AdminProductViewModel();

            vm.ProductNumber = actProductNumber;
            return(View(vm));
        }
        // GET: Admin/CategoryAssignments/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var categoryAssignment = await _context.CategoryAssignments.SingleOrDefaultAsync(m => m.ID == id);

            if (categoryAssignment == null)
            {
                return(NotFound());
            }
            List <SelectItemViewModel> catvms        = new CategoryHelper(_context).GetVmList();
            List <SelectItemViewModel> catsubvms     = new CategorySubHelper(_context).GetVmList();
            List <SelectItemViewModel> catdeatailvms = new CategoryDetailHelper(_context).GetVmList();

            ViewData["CategoryID"]       = new SelectList(catvms, "ID", "Name");
            ViewData["CategorySubID"]    = new SelectList(catsubvms, "ID", "Name");
            ViewData["CategoryDetailID"] = new SelectList(catdeatailvms, "ID", "Name");

            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Name", categoryAssignment.ProductID);
            return(View(categoryAssignment));
        }