public async Task <IActionResult> Create(Pomeshenie pomeshenie, int[] PomeshenieTypeIds)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pomeshenie);
                await _context.SaveChangesAsync();

                if (PomeshenieTypeIds != null)
                {
                    var pomeshenieTypes = new List <PomeshenieTypepomesheniya>();
                    foreach (var PomeshenieTypeId in PomeshenieTypeIds)
                    {
                        PomeshenieTypepomesheniya pomeshenieTypepomesheniya = new PomeshenieTypepomesheniya();
                        pomeshenieTypepomesheniya.PomeshenieId     = pomeshenie.PomeshenieId;
                        pomeshenieTypepomesheniya.PomeshenieTypeId = PomeshenieTypeId;
                        pomeshenieTypes.Add(pomeshenieTypepomesheniya);
                    }
                    await _context.PomeshenieTypepomesheniya.AddRangeAsync(pomeshenieTypes);

                    await _context.SaveChangesAsync();
                }


                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KorpusId"] = new SelectList(_context.Korpus, "KorpusId", "KorpusName", pomeshenie.KorpusId);
            return(View(pomeshenie));
        }
        public async Task <IActionResult> Edit(int id, Pomeshenie pomeshenie, int[] PomeshenieTypeIds)
        {
            if (id != pomeshenie.PomeshenieId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pomeshenie);
                    await _context.SaveChangesAsync();

                    if (PomeshenieTypeIds != null)
                    {
                        _context.PomeshenieTypepomesheniya.RemoveRange(_context.PomeshenieTypepomesheniya.Where(v => v.PomeshenieId == pomeshenie.PomeshenieId));
                        await _context.SaveChangesAsync();

                        var pomeshenieTypes = new List <PomeshenieTypepomesheniya>();
                        foreach (var PomeshenieTypeId in PomeshenieTypeIds)
                        {
                            PomeshenieTypepomesheniya pomeshenieTypepomesheniya = new PomeshenieTypepomesheniya();
                            pomeshenieTypepomesheniya.PomeshenieId     = pomeshenie.PomeshenieId;
                            pomeshenieTypepomesheniya.PomeshenieTypeId = PomeshenieTypeId;
                            pomeshenieTypes.Add(pomeshenieTypepomesheniya);
                        }
                        await _context.PomeshenieTypepomesheniya.AddRangeAsync(pomeshenieTypes);

                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PomeshenieExists(pomeshenie.PomeshenieId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KorpusId"] = new SelectList(_context.Korpus, "KorpusId", "KorpusName", pomeshenie.KorpusId);
            return(View(pomeshenie));
        }