////////////////////////////////////////////////////////////////////////// //Операции с библиотекарями private void LoadLibrarians() { Librarians.Clear(); sqlConnection.Open(); SqlDataReader dataReader = null; SqlCommand sqlCommandSELECT = new SqlCommand($"SELECT * From [Librarians]", sqlConnection); try { dataReader = sqlCommandSELECT.ExecuteReader(); while (dataReader.Read()) { Librarians.Add(new Librarian() { Name = (String)(Convert.ToString(dataReader["Name"])).Trim(' '), Surname = (String)(Convert.ToString(dataReader["Surname"])).Trim(' '), Patronymic = (String)(Convert.ToString(dataReader["Patronymic"])).Trim(' '), Password = (String)(Convert.ToString(dataReader["Password"])).Trim(' '), Id = Convert.ToInt32(dataReader["Id"]) }); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error); } finally { dataReader.Close(); } sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = DatabaseHelper.Retrieve(@" Select BranchName, Librarian.Id as Id, FirstName, LastName, Email, Librarian.LibraryCardNumber, Patron.Address, Patron.Zipcode, Patron.State From Librarian join Patron on (Librarian.LibraryCardNumber = Patron.LibraryCardNumber) join Library on (Librarian.LibraryId = Library.Id) "); Librarians.DataSource = dt.Rows; Librarians.DataBind(); } }
public ResultModel Update(LibrarianDataDTO model) { ResultModel result = new ResultModel(); try { if (model != null) { Librarians entity = (Librarians)model; repository.Update(entity); } } catch (Exception ex) { result.Code = OperationStatusEnum.UnexpectedError; result.Message = ex.Message; } return(result); }
public ResultModel Delete(int id) { ResultModel result = new ResultModel(); try { Librarians entity = repository.FindById(id); if (entity != null) { repository.Remove(entity); } } catch (Exception ex) { result.Code = OperationStatusEnum.UnexpectedError; result.Message = ex.Message; } return(result); }
public int Redone(int current, DateTime time) { int step = current; try { step--; List <LibrariansHistory> history; using (LibContext context = new LibContext()) { history = context.LibrariansHistory.Where(c => c.OperationDate <= time).ToList(); history.Reverse(); GenericRepository <Librarians> generic = new GenericRepository <Librarians>(context); if (step < history.Count && step >= 0) { LibrariansHistory pacient = history[step]; string operation = pacient.Operation; context.Database.ExecuteSqlCommand("DISABLE TRIGGER LibrariansHistory ON Librarians"); context.Database.ExecuteSqlCommand("DISABLE TRIGGER LibrariansInsert ON Librarians"); if (operation == "inserted") { Librarians entity = new Librarians { Id = pacient.Id, Surname = pacient.CurrentSurname, Name = pacient.CurrentName, Patronymic = pacient.CurrentPatronymic, Library = pacient.CurrentLibrary.Value, Phone = pacient.CurrentPhone, Address = pacient.CurrentAddress, UserId = pacient.CurrentUserId }; using (var scope = context.Database.BeginTransaction()) { context.Librarians.Add(entity); context.SaveChanges(); scope.Commit(); } } else if (operation == "updated") { Librarians entity = generic.Get(c => c.Id == pacient.Id).FirstOrDefault(); if (entity != null) { entity.Surname = pacient.CurrentSurname; entity.Name = pacient.CurrentName; entity.Patronymic = pacient.CurrentPatronymic; entity.Library = pacient.CurrentLibrary.Value; entity.Phone = pacient.CurrentPhone; entity.Address = pacient.CurrentAddress; entity.UserId = pacient.CurrentUserId; generic.Update(entity); } } else if (operation == "deleted") { Librarians entity = generic.Get(c => c.Id == pacient.Id).FirstOrDefault(); if (entity != null) { generic.Remove(entity); } } context.Database.ExecuteSqlCommand("ENABLE TRIGGER LibrariansHistory ON Librarians"); context.Database.ExecuteSqlCommand("ENABLE TRIGGER LibrariansInsert ON Librarians"); } } } catch (Exception ex) { throw new Exception(ex.Message); } return(step); }