bool IPearsonRepository.Create(Pearson item) { using (var session = sessionFactory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { session.Save(item); transaction.Commit(); return true; } catch (Exception ex) { transaction.Rollback(); return false; } } } }
public bool Create(Pearson item) { try { _repository.Add(item); return true; } catch (Exception ex) { //ToDo Log error return false; } }
bool IPearsonRepository.Create(Pearson item) { try { _session.Save(item); return true; } catch (Exception ex) { return false; } }
private void DosomethingWithOrders(EnumRepositoryType repoType, bool useSingleTransaction, IUnitOfWorkGeneric work, bool showMessages) { int editIndex = 0; int count = 0; try { // Get current count count = work.PearsonRepository.GetAll().Count(); lblStatistics.Text = "Total pearsons returned: " + count.ToString(); // Add new pearson and orders Pearson newPearson = new Entities.Pearson { FirstName = "Marko", LastName = "Novak" }; newPearson = work.PearsonRepository.Create(newPearson); newPearson = work.PearsonRepository.GetById(newPearson.Id); newPearson.Orders.Add(new Order { Pearson = newPearson, Price = 45, Subject = "Some demo text..." }); newPearson.Orders.Add(new Order { Pearson = newPearson, Price = 53, Subject = "More demo text..." }); // Add Orders on created pearson editIndex = GetEditIndex(count); lblStatistics.Text = lblStatistics.Text + ", Edit index: " + editIndex.ToString(); Pearson updatePearson = work.PearsonRepository.GetAll().ToArray()[editIndex]; updatePearson.Orders.Add(new Order { Pearson = updatePearson, Price = 45, Subject = "Some demo text..." }); updatePearson.Orders.Add(new Order { Pearson = updatePearson, Price = 53, Subject = "More demo text..." }); } catch (Exception ex) { MessageBox.Show("Error: \n" + ex.Message); } }
public bool Update(Pearson item) { try { //Find item and remove Pearson remove =_repository.Find(p => p.Id == item.Id); _repository.Remove(remove); // Add new _repository.Add(item); return true; } catch (Exception ex) { //ToDo Log error return false; } }
bool IPearsonRepository.Update(Pearson item) { using (var session = sessionFactory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { //IQuery query = session.CreateQuery("FROM Pearson WHERE Id = '" + item.Id.ToString() + "'"); //Pearson oldItem = query.List<Pearson>()[0]; //oldItem.LastName = item.LastName; //oldItem.FirstName = item.FirstName; session.Update(item); //delete the record transaction.Commit(); //commit it return true; } catch (Exception ex) { transaction.Rollback(); return false; } } } }
bool IPearsonRepository.Update(Pearson item) { try { //IQuery query = session.CreateQuery("FROM Pearson WHERE Id = '" + item.Id.ToString() + "'"); //Pearson oldItem = query.List<Pearson>()[0]; //oldItem.LastName = item.LastName; //oldItem.FirstName = item.FirstName; _session.Update(item); //delete the record return true; } catch (Exception ex) { return false; } }