public static int SaveOrUpdateCourt(Court court) { lock (DBHelper.Lock) { if (DBHelper.DBWrapper.IsTableExists <TblCourt>()) { //var result = GetCourtDetail(court.ID, court.GuId); var result = GetCourtDetail(court.ID); if (result != null && result.Item1 != null) { return(DBHelper.DBWrapper.Update("Update TblCourt set " + "Name = ?, IsOccupied =? " + "where GuId = ? or ID = ?" , new object[] { court.Name, court.IsOccupied, court.GuId, court.ID })); } } var tblCourtRow = new TblCourt() { ID = court.ID, GuId = court.GuId, Name = court.Name, IsOccupied = court.IsOccupied, }; return(DBHelper.DBWrapper.InsertNewRow <TblCourt>(tblCourtRow)); } }
//Initialise once. Create a fixed list of courts into db. //Todo need to return data from db. So that ID will have value instead of 0. public static List <Court> InitCourtDetail(List <Court> maxListOfCourts) { lock (DBHelper.Lock) { try { if (DBHelper.DBWrapper.IsTableExists <TblCourt>()) { var deleted = DBHelper.DBWrapper.DeleteAllData <TblCourt>(); System.Diagnostics.Debug.WriteLine("Deleted :" + deleted); } foreach (var c in maxListOfCourts) { var tblCourtRow = new TblCourt() { GuId = c.GuId, Name = c.Name, IsOccupied = c.IsOccupied }; DBHelper.DBWrapper.InsertNewRow <TblCourt>(tblCourtRow); } return(GetAllCourtDetails().Item1); }catch (Exception ex) { return(null); } } }