private void Save(PetaPoco.Database db, int[] ChannelOids = null) { if (!IsShared) { this.Name = this.Name.Trim(); // sanity checks if (String.IsNullOrWhiteSpace(this.Name)) throw new ArgumentException("Name must not be blank."); if (db.FirstOrDefault<int>("select count(*) from channelgroup where useroid = @0 and name = @1 and oid <> @2", this.UserOid, this.Name, this.Oid) > 0) throw new ArgumentException("A group with the name '{0}' already exists.".FormatStr(this.Name)); } if (this.Oid == 0) // new group { this.OrderOid = db.FirstOrDefault<int>("select ifnull(max(orderoid),0) + 1 from channelgroup where useroid = @0", this.UserOid); if (this.IsShared) { // special case, insert missing shared, so need to make sure name isnt inserted as it comes from the parent channel group this.Name = ""; } db.Insert("channelgroup", "oid", true, this); if (this.Oid < 1) throw new Exception("Failed to insert channel group."); } else // update { // only allow updating of the name here.. maybe add order too? if(IsShared) db.Update(this, this.Oid, new string[] { "orderoid", "enabled" }); else db.Update(this, this.Oid, new string[] { "name", "orderoid" }); } if (ChannelOids != null && !IsShared) { // insert the channels db.Execute("delete from channelgroupchannel where channelgroupoid = @0", this.Oid); foreach (int channeloid in ChannelOids) db.Execute("insert into channelgroupchannel (channelgroupoid, channeloid) values (@0, @1)", this.Oid, channeloid); } }
public bool Save(PetaPoco.Database db = null) { if(db == null) db = DbHelper.GetDatabase(); if (this._Channels == null) this._Channels = ""; if (this.LastScanTime < System.Data.SqlTypes.SqlDateTime.MinValue.Value) this.LastScanTime = System.Data.SqlTypes.SqlDateTime.MinValue.Value; if (this.Oid < 1) return db.Insert("xmltvsource", "oid", true, this) != null; else return db.Update(this) > 0; }