public bool Save() { bool result = false; Database db = DatabaseFactory.CreateDatabase(Constants.CONNECTIONSTRING); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { HouseDAO houseDAO = new HouseDAO(); //If landlord user is a partial user, this logic might need to change if (!new LandlordDAO().IsLandlordExist(new Landlord() { LandlordId = this.LandlordId })) { new Landlord() { LandlordId = this.LandlordId, LandlordTypeId = (int)Enums.LandlordType.SimpleLandlord, CreatedBy = this.CreatedBy }.Save(); } if (houseDAO.IsHouseExist(this)) { result = houseDAO.Update(this, db, transaction); } else { result = houseDAO.Insert(this, db, transaction); } if (result) { transaction.Commit(); } else { transaction.Rollback(); } } catch (System.Exception ex) { transaction.Rollback(); result = false; throw ex; } finally { connection.Close(); } return(result); }
public bool Save(House house) { bool result = false; Database db = DatabaseFactory.CreateDatabase(Constants.CONNECTIONSTRING); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { HouseDAO houseDAO = new HouseDAO(); // House house = new House(); if (houseDAO.IsHouseExist(house)) { result = new HouseOptionDAO().Delete(new HouseOption() { HouseId = house.HouseId.Value }, db, transaction); if (house.HouseOptionList != null) { foreach (HouseOption item in house.HouseOptionList) { new HouseOptionDAO().Insert(item, db, transaction); } } } if (result) { transaction.Commit(); } else { transaction.Rollback(); } } catch (System.Exception ex) { transaction.Rollback(); result = false; throw ex; } finally { connection.Close(); } return(result); }
public bool Save(House house) { bool result = false; Database db = DatabaseFactory.CreateDatabase(Constants.CONNECTIONSTRING); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { HouseDAO houseDAO = new HouseDAO(); // House house = new House(); if (houseDAO.IsHouseExist(house)) { result = new HouseOptionDAO().Delete(new HouseOption() { HouseId = house.HouseId.Value }, db, transaction); if (house.HouseOptionList != null) { foreach (HouseOption item in house.HouseOptionList) { new HouseOptionDAO().Insert(item, db, transaction); } } } if (result) { transaction.Commit(); } else { transaction.Rollback(); } } catch (System.Exception ex) { transaction.Rollback(); result = false; throw ex; } finally { connection.Close(); } return result; }
public bool Save() { bool result = false; Database db = DatabaseFactory.CreateDatabase(Constants.CONNECTIONSTRING); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { HouseDAO houseDAO = new HouseDAO(); //If landlord user is a partial user, this logic might need to change if (!new LandlordDAO().IsLandlordExist(new Landlord() { LandlordId = this.LandlordId })) { new Landlord() { LandlordId = this.LandlordId, LandlordTypeId = (int)Enums.LandlordType.SimpleLandlord, CreatedBy = this.CreatedBy }.Save(); } if (houseDAO.IsHouseExist(this)) { result = houseDAO.Update(this, db, transaction); } else { result = houseDAO.Insert(this, db, transaction); } if (result) { transaction.Commit(); } else { transaction.Rollback(); } } catch (System.Exception ex) { transaction.Rollback(); result = false; throw ex; } finally { connection.Close(); } return result; }