예제 #1
0
        public async Task <IActionResult> Create([Bind("ProductPhotoId,ProductId,PhotoFilename")] ProductPhoto productPhoto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productPhoto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "Name", productPhoto.ProductId);
            return(View(productPhoto));
        }
        public async Task <IActionResult> Create([Bind("CategoryId,Name")] Category category)
        {
            category.Name = category.Name.Trim();
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("UnitId,Name")] Unit unit)
        {
            if (ModelState.IsValid)
            {
                unit.Name = unit.Name.Trim();
                _context.Add(unit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(unit));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("StateId,Name")] State state)
        {
            state.Name = state.Name.Trim();
            if (ModelState.IsValid)
            {
                _context.Add(state);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(state));
        }
        public async Task <IActionResult> Create([Bind("UserId,Username,Password,Family,Name,Mobile,IsAdmin")] User user)
        {
            user.Username = user.Username.Trim();
            if (ModelState.IsValid)
            {
                user.Password = _hashHelper.GetMD5(user.Password);
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("CityId,StateId,Name")] City city)
        {
            city.Name = city.Name.Trim();
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StateId"] = new SelectList(_context.State, "StateId", "Name", city.StateId);
            return(View(city));
        }
        public async Task <IActionResult> Create([Bind("SubcategoryId,CategoryId,Name")] Subcategory subcategory)
        {
            subcategory.Name = subcategory.Name.Trim();
            if (ModelState.IsValid)
            {
                _context.Add(subcategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "Name", subcategory.CategoryId);
            return(View(subcategory));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("ProductAttributeValueId,ProductId,ProductAttributeId,Value")] ProductAttributeValue productAttributeValue)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productAttributeValue);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"]          = new SelectList(_context.Product, "ProductId", "Name", productAttributeValue.ProductId);
            ViewData["ProductAttributeId"] = new SelectList(_context.ProductAttribute, "ProductAttributeId", "Name", productAttributeValue.ProductAttributeId);
            return(View(productAttributeValue));
        }
        public async Task <IActionResult> Create([Bind("ProductAttributeId,Name,UnitId")] ProductAttribute productAttribute)
        {
            productAttribute.Name = productAttribute.Name.Trim();
            if (ModelState.IsValid)
            {
                _context.Add(productAttribute);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UnitId"] = new SelectList(_context.Unit, "UnitId", "Name", productAttribute.UnitId);
            return(View(productAttribute));
        }
예제 #10
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var order = await _context.Order.FindAsync(id);

            _context.Order.Remove(order);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create([Bind("ProductId,SubcategoryId,Name,UnitPrice")] Product product, IFormFile photoFile)
        {
            if (photoFile != null)
            {
                string       photoFilename = $"{Guid.NewGuid().ToString()}.jpg";
                MemoryStream stream        = new MemoryStream();
                photoFile.CopyTo(stream);
                new ImageFactory().Load(stream.GetBuffer())
                .Resize(new Size(640, 640))
                .Format(new JpegFormat())
                .Save($"{_hostEnvironment.ContentRootPath}\\wwwroot\\files\\productphotos\\{photoFilename}");
                product.PhotoFilename = photoFilename;
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubcategoryId"] = new SelectList(_context.Subcategory, "SubcategoryId", "Name", product.SubcategoryId);
            return(View(product));
        }