public async Task <IActionResult> Edit(int id, [Bind("ConferenceAndParticipantId,ParticipantId,ConferenceId")] ConferencesAndParticipant conferencesAndParticipant) { if (id != conferencesAndParticipant.ConferenceAndParticipantId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(conferencesAndParticipant); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConferencesAndParticipantExists(conferencesAndParticipant.ConferenceAndParticipantId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ConferenceId"] = new SelectList(_context.Conferences, "ConferenceId", "Aim", conferencesAndParticipant.ConferenceId); ViewData["ParticipantId"] = new SelectList(_context.Participants, "ParticipantId", "FullName", conferencesAndParticipant.ParticipantId); return(View(conferencesAndParticipant)); }
public async Task <IActionResult> Create([Bind("ConferenceAndParticipantId,ParticipantId,ConferenceId")] ConferencesAndParticipant conferencesAndParticipant) { if (ModelState.IsValid) { _context.Add(conferencesAndParticipant); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ConferenceId"] = new SelectList(_context.Conferences, "ConferenceId", "Aim", conferencesAndParticipant.ConferenceId); ViewData["ParticipantId"] = new SelectList(_context.Participants, "ParticipantId", "FullName", conferencesAndParticipant.ParticipantId); return(View(conferencesAndParticipant)); }
public async Task <IActionResult> Import(IFormFile fileExcel) { if (ModelState.IsValid) { if (fileExcel != null) { using (var stream = new FileStream(fileExcel.FileName, FileMode.Create)) { await fileExcel.CopyToAsync(stream); using (XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled)) { foreach (IXLWorksheet worksheet in workBook.Worksheets) { Location newloc; var l = (from loc in _context.Locations where loc.City.Contains(worksheet.Name) select loc).ToList(); if (l.Count() > 0) { newloc = l[0]; } else { newloc = new Location(); newloc.City = worksheet.Name; newloc.Country = "можливо Україна"; newloc.Capacity = 0; _context.Locations.Add(newloc); } foreach (IXLRow row in worksheet.RowsUsed()) { //try //{ int counter = 1; Conference conf = new Conference(); DateTime date = new DateTime(2020, 1, 1); conf.Title = row.Cell(1).Value.ToString(); conf.FormId = Convert.ToInt32(row.Cell(2).Value); conf.OrganizerId = Convert.ToInt32(row.Cell(3).Value); conf.Aim = "невідомо"; conf.Topic = "невідомо"; conf.RequirementsForWorks = "невідомо"; conf.RequirementsForParticipants = "невідомо"; conf.Price = 0; conf.DateAndTime = date; conf.Location = newloc; _context.Conferences.Add(conf); for (int i = 4; i <= 30; i++) { if (row.Cell(i).Value.ToString().Length > 0) { Participant participant; var p = (from par in _context.Participants where par.FullName.Contains(row.Cell(i).Value.ToString()) select par).ToList(); if (p.Count > 0) { participant = p[0]; } else { participant = new Participant(); participant.FullName = row.Cell(i).Value.ToString(); DateTime date1 = new DateTime(1980, 1, 1); participant.BirthDate = date1; participant.Occupation = "невідомо"; participant.Institution = "невідомо"; _context.Add(participant); } ConferencesAndParticipant cap = new ConferencesAndParticipant(); cap.Conference = conf; cap.Participant = participant; _context.ConferencesAndParticipants.Add(cap); } } //} //catch (Exception ex) //{ } } } } } } await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }