Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Category,Manufacturer,Model,Photo")] Techlist techlist)
        {
            if (id != techlist.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(techlist);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TechlistExists(techlist.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(techlist));
        }
Пример #2
0
        public async Task <IActionResult> Create(CategoryCreateViewModel category)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (category.Path != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "img");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + category.Path.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    category.Path.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                Techlist category1 = new Techlist
                {
                    Category     = Convert.ToInt32(category.NameCat),
                    Model        = Convert.ToInt32(category.NameMod),
                    Manufacturer = Convert.ToInt32(category.NameMan),
                    Photo        = uniqueFileName
                };
                _context.Add(category1);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Пример #3
0
        public IActionResult Privacy(AddForm add)
        {
            Techlist techlist = new Techlist
            {
                Category     = add.Category,
                Manufacturer = add.Manufacturer,
                Model        = add.Model,
                Photo        = "img/5.png"
            };

            db.Techlist.Add(techlist);
            db.SaveChanges();
            return(RedirectToAction("Privacy"));
        }