public async Task <IActionResult> Edit(int id, [Bind("UchPosobieVidId,UchPosobieVidName")] UchPosobieVid uchPosobieVid)
        {
            if (id != uchPosobieVid.UchPosobieVidId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(uchPosobieVid);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UchPosobieVidExists(uchPosobieVid.UchPosobieVidId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(uchPosobieVid));
        }
        public async Task <IActionResult> Create([Bind("UchPosobieVidId,UchPosobieVidName")] UchPosobieVid uchPosobieVid)
        {
            if (ModelState.IsValid)
            {
                _context.Add(uchPosobieVid);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(uchPosobieVid));
        }
Beispiel #3
0
        /// <summary>
        /// Инициализация таблицы "Вид учебного пособия"
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task CreateUchPosobieVid(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>();

                #region Инициализация таблицы "Вид учебного пособия"
                if (!await context.UchPosobieVid.AnyAsync())
                {
                    UchPosobieVid UchPosobieVidName1 = new UchPosobieVid
                    {
                        UchPosobieVidId   = 1,
                        UchPosobieVidName = "Учебное пособие",
                    };

                    UchPosobieVid UchPosobieVidName2 = new UchPosobieVid
                    {
                        UchPosobieVidId   = 2,
                        UchPosobieVidName = "Курс лекций",
                    };

                    UchPosobieVid UchPosobieVidName3 = new UchPosobieVid
                    {
                        UchPosobieVidId   = 3,
                        UchPosobieVidName = "Лабораторный практикум",
                    };

                    UchPosobieVid UchPosobieVidName4 = new UchPosobieVid
                    {
                        UchPosobieVidId   = 4,
                        UchPosobieVidName = "Методические указания",
                    };

                    await context.UchPosobieVid.AddRangeAsync(
                        UchPosobieVidName1,
                        UchPosobieVidName2,
                        UchPosobieVidName3,
                        UchPosobieVidName4
                        );

                    await context.SaveChangesAsync();
                }
                #endregion
            }
        }