Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("NirTemaId,NirTemaName")] NirTema nirTema, int[] EduProfileIds)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nirTema);
                await _context.SaveChangesAsync();

                if (EduProfileIds != null)
                {
                    var NirTemaEduProfile = new List <NirTemaEduProfile>();
                    foreach (var EduProfileId in EduProfileIds)
                    {
                        NirTemaEduProfile nirTemaEduProfile = new NirTemaEduProfile();
                        nirTemaEduProfile.EduProfileId = EduProfileId;
                        nirTemaEduProfile.NirTemaId    = nirTema.NirTemaId;
                        NirTemaEduProfile.Add(nirTemaEduProfile);
                    }
                    await _context.NirTemaEduProfile.AddRangeAsync(NirTemaEduProfile);

                    await _context.SaveChangesAsync();
                }

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

            List <EduProfile> EduProfiles = _context.EduProfiles
                                            .Include(p => p.EduNapravl.EduUgs.EduLevel)
                                            .ToList();

            ViewData["EduProfiles"] = EduProfiles;

            return(View(nirTema));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("NirTemaEduProfileId,NirTemaId,EduProfileId")] NirTemaEduProfile nirTemaEduProfile)
        {
            if (id != nirTemaEduProfile.NirTemaEduProfileId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(nirTemaEduProfile);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NirTemaEduProfileExists(nirTemaEduProfile.NirTemaEduProfileId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EduProfileId"] = new SelectList(_context.EduProfiles.Include(m => m.EduNapravl.EduUgs.EduLevel), "EduProfileId", "GetEduProfileFullName", nirTemaEduProfile.EduProfileId);
            ViewData["NirTemaId"]    = new SelectList(_context.NirTema, "NirTemaId", "NirTemaName", nirTemaEduProfile.NirTemaId);
            return(View(nirTemaEduProfile));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("NirTemaEduProfileId,NirTemaId,EduProfileId")] NirTemaEduProfile nirTemaEduProfile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nirTemaEduProfile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EduProfileId"] = new SelectList(_context.EduProfiles.Include(m => m.EduNapravl.EduUgs.EduLevel), "EduProfileId", "GetEduProfileFullName", nirTemaEduProfile.EduProfileId);
            ViewData["NirTemaId"]    = new SelectList(_context.NirTema, "NirTemaId", "NirTemaName", nirTemaEduProfile.NirTemaId);



            return(View(nirTemaEduProfile));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("NirTemaId,NirTemaName")] NirTema nirTema, int[] EduProfileIds)
        {
            if (id != nirTema.NirTemaId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(nirTema);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NirTemaExists(nirTema.NirTemaId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (EduProfileIds != null)
                {
                    _context.NirTemaEduProfile.RemoveRange(_context.NirTemaEduProfile.Where(y => y.NirTemaId == nirTema.NirTemaId));
                    await _context.SaveChangesAsync();

                    var NirTemaEduProfile = new List <NirTemaEduProfile>();
                    foreach (var EduProfileId in EduProfileIds)
                    {
                        NirTemaEduProfile nirTemaEduProfile = new NirTemaEduProfile();
                        nirTemaEduProfile.EduProfileId = EduProfileId;
                        nirTemaEduProfile.NirTemaId    = nirTema.NirTemaId;
                        NirTemaEduProfile.Add(nirTemaEduProfile);
                    }
                    await _context.NirTemaEduProfile.AddRangeAsync(NirTemaEduProfile);

                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(nirTema));
        }