/// <summary> /// Инициализация таблицы "Электронные библиотечные системы" /// </summary> /// <param name="serviceProvider"></param> /// <param name="configuration"></param> /// <returns></returns> public static async Task CreateElectronBiblSystem(IServiceProvider serviceProvider, IConfiguration configuration) { using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>(); #region Инициализация таблицы "Электронные библиотечные системы" if (!await context.ElectronBiblSystem.AnyAsync()) { ElectronBiblSystem Ebs1 = new ElectronBiblSystem { NameEbs = "Издательство \"Лань\"", LinkEbs = "https://e.lanbook.com ", NumberDogovor = "1723", DateStart = new DateTime(2016, 12, 14) }; ElectronBiblSystem Ebs2 = new ElectronBiblSystem { NameEbs = "ООО \"НексМедиа\"", LinkEbs = "http://biblioclub.ru/index.php?page=main_ub_red ", NumberDogovor = "008-01/2017", DateStart = new DateTime(2017, 01, 19), DateEnd = new DateTime(2018, 01, 19) }; await context.ElectronBiblSystem.AddRangeAsync(Ebs1, Ebs2); await context.SaveChangesAsync(); } #endregion } }
public async Task <IActionResult> Edit(int id, [Bind("ElectronBiblSystemId,NameEbs,LinkEbs,NumberDogovor,DateStart,DateEnd,CopyDogovorId")] ElectronBiblSystem electronBiblSystem, IFormFile uploadedFile) { if (id != electronBiblSystem.ElectronBiblSystemId) { return(NotFound()); } if (ModelState.IsValid) { try { if (uploadedFile != null) { int?fileModelIdToRemove = electronBiblSystem.CopyDogovorId; var fileModel = await _fileModelRepository.UploadElectronBiblSystemDogovorAsync(uploadedFile); electronBiblSystem.CopyDogovorId = fileModel.Id; await _fileModelRepository.RemoveFileAsync(fileModelIdToRemove); } _context.Update(electronBiblSystem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ElectronBiblSystemExists(electronBiblSystem.ElectronBiblSystemId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(electronBiblSystem)); }
public async Task <IActionResult> Create([Bind("ElectronBiblSystemId,NameEbs,LinkEbs,NumberDogovor,DateStart,DateEnd,CopyDogovorId")] ElectronBiblSystem electronBiblSystem, IFormFile uploadedFile) { if (ModelState.IsValid) { if (uploadedFile != null) { var fileModel = await _fileModelRepository.UploadElectronBiblSystemDogovorAsync(uploadedFile); if (fileModel != null) { electronBiblSystem.CopyDogovorId = fileModel.Id; } } _context.Add(electronBiblSystem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(electronBiblSystem)); }