public void CreateCourtAndLinkToFacility(int facilityId, ref Court court) { //Save the court record var insertedRowId = _da.Value.Court.Insert(court); if (insertedRowId == 0) { throw new Exception("Failed to create court record"); } else { court.Id = insertedRowId; } //Link the court and facility records var facilityCourtLink = new LinkObjectMaster() { MasterLinkId = facilityId, MasterLinkType = LinkType.Facility, ChildLinkId = court.Id, ChildLinkType = LinkType.Court }; //Save the link record insertedRowId = _da.Value.Link.Insert(facilityCourtLink); if (insertedRowId == 0) { //Roll back the inserts as it's failed //Delete the court record _da.Value.Court.Delete(court); throw new Exception("Failed to create facility court link record, transaction rolled back"); } }
public void Delete(Court deleteThis) { _dataEngine.InitialiseParameterList(); _dataEngine.AddParameter("@Id", deleteThis.Id.ToString()); _sqlToExecute = "DELETE FROM [dbo].[Court] WHERE Id = " + _dataEngine.GetParametersForQuery(); if (!_dataEngine.ExecuteSql(_sqlToExecute)) throw new Exception("Court - Delete failed"); }
public int Insert(Court saveThis) { try { _db.Courts.InsertOnSubmit(saveThis); _db.SubmitChanges(); return saveThis.Id; } catch (Exception e) { throw new Exception(e.Message); } }
public void Delete(Court deleteThis) { try { if (deleteThis.Id > 0) { _db.Courts.DeleteOnSubmit(deleteThis); _db.SubmitChanges(ConflictMode.FailOnFirstConflict); } } catch (Exception e) { throw new Exception(e.Message); } }
public void Update(Court updateThis) { try { _db.Courts.Attach(updateThis); _db.Refresh(RefreshMode.KeepCurrentValues, updateThis); _db.SubmitChanges(); } catch (Exception e) { throw new Exception(e.Message); } }
public int Insert(Court saveThis) { _dataEngine.InitialiseParameterList(); _dataEngine.AddParameter("@CourtDescription", saveThis.CourtDescription); _sqlToExecute = "INSERT INTO [dbo].[Court] "; _sqlToExecute += "([CourtDescription]) "; _sqlToExecute += "OUTPUT INSERTED.Id "; _sqlToExecute += "VALUES "; _sqlToExecute += "("; _sqlToExecute += _dataEngine.GetParametersForQuery(); _sqlToExecute += ")"; int insertedRowId = 0; if (!_dataEngine.ExecuteSql(_sqlToExecute, out insertedRowId)) throw new Exception("Court - Save failed"); return insertedRowId; }
/// <summary> /// Creates the object from the data returned from the database /// </summary> /// <returns></returns> private Court CreateCourtFromData() { var court = new Court { Id = int.Parse(_dataEngine.Dr["Id"].ToString()), CourtDescription = _dataEngine.Dr["CourtDescription"].ToString() }; return court; }
public void Update(Court saveThis) { _dataEngine.InitialiseParameterList(); _dataEngine.AddParameter("@CourtDescription", saveThis.CourtDescription); _sqlToExecute = "UPDATE [dbo].[Court] SET "; _sqlToExecute += "[CourtDescription] = @CourtDescription "; _sqlToExecute += "WHERE [Id] = " + saveThis.Id; if (!_dataEngine.ExecuteSql(_sqlToExecute)) throw new Exception("Court - Update failed"); }