public async Task <IActionResult> Edit(int id, [Bind("Id,TypeId")] Abonements abonements) { if (id != abonements.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(abonements); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AbonementsExists(abonements.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["TypeId"] = new SelectList(_context.AbonementTypes, "Id", "Type", abonements.TypeId); return(View(abonements)); }
public async Task <IActionResult> Create([Bind("Id,TypeId")] Abonements abonements) { if (ModelState.IsValid) { _context.Add(abonements); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TypeId"] = new SelectList(_context.AbonementTypes, "Id", "Type", abonements.TypeId); return(View(abonements)); }
////////////////////////////////////////////////////////////////////////// //Операции с абонементами private void LoadAbonements() { Abonements.Clear(); sqlConnection.Open(); SqlDataReader dataReader = null; SqlCommand sqlCommandSELECT = new SqlCommand($"SELECT * From [Abonements], [Passports] WHERE [Abonements].[Passport_Id] = [Passports].[Id] ORDER BY [Surname]", sqlConnection); try { dataReader = sqlCommandSELECT.ExecuteReader(); while (dataReader.Read()) { Abonements.Add(new Abonement() { Passport = new Passport() { Country = (String)(Convert.ToString(dataReader["Country"])).Trim(' '), }, Surname = (String)(Convert.ToString(dataReader["Surname"])).Trim(' '), Name = (String)(Convert.ToString(dataReader["Name"])).Trim(' '), Patronymic = (String)(Convert.ToString(dataReader["Patronymic"])).Trim(' '), Address = (String)(Convert.ToString(dataReader["Address"])).Trim(' '), ContactPhoneNumber = (String)(Convert.ToString(dataReader["ContactPhoneNumber"])).Trim(' '), Id = Convert.ToInt32(dataReader["Id"]) }); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error); } finally { dataReader.Close(); } sqlConnection.Close(); }
private void SearchAUpdate() { if (SearchA.Text.Length > 0) { if (SearchA.Text.Length < searchLengthOldA) { LoadAbonements(); } searchLengthOldA = SearchA.Text.Length; SearchAWatermark.Visibility = Visibility.Hidden; string search = SearchA.Text; for (int i = 0; i < Abonements.Count; i++) { string str = ""; str += Abonements[i].Passport.Country; str += Abonements[i].Id; str += Abonements[i].Name; str += Abonements[i].Patronymic; str += Abonements[i].Surname; str += Abonements[i].ContactPhoneNumber; str += Abonements[i].Address; str += str.ToLower() + str.ToUpper(); int ind = str.IndexOf(search); if (ind == -1) { Abonements.RemoveAt(i); i--; } } } else { LoadAbonements(); SearchAWatermark.Visibility = Visibility.Visible; } }
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) { foreach (IXLRow row in worksheet.RowsUsed().Skip(1)) { try { Students stud = new Students(); stud.Name = row.Cell(1).Value.ToString(); stud.Photo = row.Cell(2).Value.ToString(); stud.ProfileDescription = row.Cell(3).Value.ToString(); _context.Students.Add(stud); if (row.Cell(4).Value.ToString().Length > 0) { { AbonementTypes abtype; var a = (from abtyp in _context.AbonementTypes where abtyp.Type.Contains(row.Cell(4).Value.ToString()) select abtyp).ToList(); if (a.Count > 0) { { abtype = a[0]; } } else { abtype = new AbonementTypes(); abtype.Type = row.Cell(4).Value.ToString(); _context.AbonementTypes.Add(abtype); } Abonements ab = new Abonements(); ab.Type = abtype; ab.TypeId = abtype.Id; _context.Abonements.Add(ab); string dateString = row.Cell(5).Value.ToString(); DateTime dateFromString = DateTime.Parse(dateString, System.Globalization.CultureInfo.InvariantCulture); StudentAbonements st = new StudentAbonements(); st.Stud = stud; st.Abon = ab; st.AbonId = ab.Id; st.StudId = stud.Id; st.ActivationDate = dateFromString; _context.StudentAbonements.Add(st); } } } catch (Exception e) { } } } } } } await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }