Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,Website")] Factory factory)
        {
            if (ModelState.IsValid)
            {
                var f = _context.Factory.Where(c => c.Name == factory.Name && c.Address == factory.Address).FirstOrDefault();
                if (f != null)
                {
                    ModelState.AddModelError(string.Empty, "Фабрика з такою назвою та за такою ж адресою вже існує");
                }
                _context.Add(factory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(factory));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Garbage garbage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(garbage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(garbage));
        }
        public async Task <IActionResult> Create(int IdFactory, [Bind("Id,IdGarbageType,IdFactory")] FactoryGarbageType factoryGarbageType)
        {
            factoryGarbageType.IdFactory = IdFactory;
            if (ModelState.IsValid)
            {
                _context.Add(factoryGarbageType);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "FactoryGarbageTypes", new { id = IdFactory }));
            }
            ViewData["IdFactory"]     = new SelectList(_context.Factory, "Id", "Name", factoryGarbageType.IdFactory);
            ViewData["IdGarbageType"] = new SelectList(_context.GarbageType, "Id", "Name", factoryGarbageType.IdGarbageType);
            return(View(factoryGarbageType));
        }
        public async Task <IActionResult> Create(int idGarbage, [Bind("Id,IdGarbage,IdMaterial")] GarbageMaterial garbageMaterial)
        {
            garbageMaterial.IdGarbage = idGarbage;
            if (ModelState.IsValid)
            {
                _context.Add(garbageMaterial);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "GarbageMaterials",
                                        new { id = idGarbage, name = _context.Garbage.Where(c => c.Id == idGarbage).FirstOrDefault().Name }));
            }
            ViewData["IdGarbage"]  = new SelectList(_context.Garbage, "Id", "Name", garbageMaterial.IdGarbage);
            ViewData["IdMaterial"] = new SelectList(_context.Material, "Id", "Name", garbageMaterial.IdMaterial);
            return(View(garbageMaterial));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,MaterialCard,IdGarbageType,Info")] Material material)
        {
            if (ModelState.IsValid)
            {
                var m = _context.Material.Where(c => c.MaterialCard == material.MaterialCard).FirstOrDefault();
                if (m != null)
                {
                    ModelState.AddModelError(string.Empty, "Матеріал з таким ідентифікатором вже існує");
                }
                _context.Add(material);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdGarbageType"] = new SelectList(_context.GarbageType, "Id", "Name", material.IdGarbageType);
            return(View(material));
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("Id,Name")] GarbageType garbageType)
        {
            if (ModelState.IsValid)
            {
                var garbagetype = _context.GarbageType.Where(g => g.Name == garbageType.Name).FirstOrDefault();
                if (garbagetype != null)
                {
                    ModelState.AddModelError(string.Empty, "Даний тип сміття вже існує");
                }
                else
                {
                    _context.Add(garbageType);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(garbageType));
        }