Пример #1
0
        public void saveChanges()
        {
            using (var db = new PlanningContext())
            {
                bbc_rss_visibility data = null;

                if (!this._isCreateMode)
                {
                    var id = Convert.ToInt32(this.bbc_rss_visibility_id.Text);
                    data = db.bbc_rss_visibility.Where(d => d.bbc_rss_visibility_id == id).FirstOrDefault();
                    if (data == null)
                    {
                        this._mainInterface.statusText = $"ERROR: ID '{this.bbc_rss_visibility_id.Text}' does not exist.";
                        return;
                    }
                }
                else
                {
                    data = new bbc_rss_visibility();
                }

                data.bbc_rss_visibility_id = Convert.ToInt32(this.bbc_rss_visibility_id.Text);
                data.description           = /**/ (this.description.Text);
                data.comment   = /**/ (this.comment.Text);
                data.is_active = (bool)this.is_active.IsChecked;


                if (this._isCreateMode)
                {
                    db.bbc_rss_visibility.Add(data);
                }
                db.SaveChanges();
            }
        }
Пример #2
0
        public static bbc_rss_visibility GetVisibility(string visiblity, bool createIfMissing = true)
        {
            visiblity = visiblity.ToUpper().Trim();
            using (var db = new PlanningContext())
            {
                var query = from db_visiblity in db.bbc_rss_visibility
                            where db_visiblity.description.ToUpper() == visiblity
                            select db_visiblity;

                var result = query.FirstOrDefault();

                if (result == null && createIfMissing)
                {
                    var toAdd = new bbc_rss_visibility
                    {
                        description = visiblity,
                        version     = 1,
                        is_active   = true,
                        comment     = visiblity
                    };

                    db.bbc_rss_visibility.Add(toAdd);
                    db.SaveChanges();

                    result = toAdd;
                }

                return(result);
            }
        }
        public void deleteItem(object item)
        {
            if (item == null)
            {
                return;
            }

            bbc_rss_visibility data = item as bbc_rss_visibility;

            if (data == null)
            {
                return;
            }

            using (var db = new PlanningContext())
            {
                db.bbc_rss_visibility.Remove(db.bbc_rss_visibility.Where(d => d.bbc_rss_visibility_id == data.bbc_rss_visibility_id).First());
                db.SaveChanges();
            }
        }