Exemplo n.º 1
0
        public Category Update(Category c)
        {
            Requires.NotNull(c);
            Requires.PropertyNotNegative(c, "CategoryID");

            string valReason = "";

            if (!this.validateCategoryUrlNotInUse(c.URL, c.ModuleId, c.CategoryID, out valReason))
            {
                throw (new Exception("URL already in use"));
            }

            using (IDataContext ctx = DataContext.Instance())
            {
                var rep         = ctx.GetRepository <Category>();
                var cntTaxonomy = new DNNContent();
                cntTaxonomy.UpdateContentItem(c);
                rep.Update(c);
                if (c != null && c.ImageFileID > 0)
                {
                    c.Image = new Components.Entities.File(FileManager.Instance.GetFile((int)c.ImageFileID));
                }
            }
            return(c);
        }
Exemplo n.º 2
0
        public Article Update(Article a)
        {
            Requires.NotNull(a);
            //Requires.PropertyNotNegative(a, "ArticleID"); - can't be used becuase it's a long and not an int

            string valReason = "";

            if (!this.validateArticleUrlNotInUse(a.URL, a.ModuleId, a.ArticleID, out valReason))
            {
                throw (new Exception("URL already in use"));
            }

            using (IDataContext ctx = DataContext.Instance())
            {
                //var frep = ctx.GetRepository<File>();
                //var dbaFiles = frep.Find("WHERE ArticleID=@0", a.ArticleID).ToList();
                try
                {
                    ctx.BeginTransaction();
                    var rep         = ctx.GetRepository <Article>();
                    var cntTaxonomy = new DNNContent();
                    cntTaxonomy.UpdateContentItem(a);
                    rep.Update(a);
                    UpsertCategories(a, ctx);
                    UpsertTags(a, ctx);
                    UpsertPages(a, ctx);
                    UpsertFiles(a, ctx);
                    UpsertImages(a, ctx);
                    ctx.Commit();
                }
                catch (Exception)
                {
                    ctx.RollbackTransaction();
                    throw;
                }
            }
            return(a);
        }