Esempio n. 1
0
        /// <summary>
        /// Возвращает версию статьи
        /// </summary>
        /// <param name="id">ID версии</param>
        /// <param name="articleId">ID статьи (параметр необязательный, необходимо передавать только, если версия - текущая</param>
        /// <returns>информация о версии статьи</returns>
        internal static ArticleVersion GetById(int id, int articleId = 0)
        {
            ArticleVersion articleVersion;

            if (id == ArticleVersion.CurrentVersionId)
            {
                if (articleId == 0)
                {
                    throw new Exception("Article id is not specified!");
                }

                var article = ArticleRepository.GetById(articleId);
                articleVersion = new ArticleVersion {
                    ArticleId = articleId, Id = id, Modified = article.Modified, LastModifiedBy = article.LastModifiedBy, LastModifiedByUser = article.LastModifiedByUser, Article = article
                };
            }
            else
            {
                var articleVersionDal = DefaultRepository.GetById <ArticleVersionDAL>(id);
                if (articleVersionDal == null)
                {
                    return(null);
                }

                articleVersionDal.LastModifiedByUserReference.Load();

                articleVersion = MapperFacade.ArticleVersionMapper.GetBizObject(articleVersionDal);
                if (articleVersion != null)
                {
                    articleVersion.Article = ArticleRepository.GetById(articleVersion.ArticleId);
                }
            }

            return(articleVersion);
        }
Esempio n. 2
0
 public bool updateBaseAA(int id, int activity_type_id, string activity_name, string location, string from, string to)
 {
     using (DbContextTransaction transaction = db.Database.BeginTransaction())
     {
         try
         {
             ENTITIES.AcademicActivity aa = db.AcademicActivities.Find(id);
             aa.activity_date_start = DateTime.ParseExact(from, "dd/MM/yyyy", CultureInfo.InvariantCulture);
             aa.activity_date_end   = DateTime.ParseExact(to, "dd/MM/yyyy", CultureInfo.InvariantCulture);
             aa.activity_type_id    = activity_type_id;
             db.Entry(aa).State     = EntityState.Modified;
             db.SaveChanges();
             AcademicActivityLanguage al = db.AcademicActivityLanguages.Where(x => x.activity_id == id && x.language_id == 1).FirstOrDefault();
             al.location        = location;
             db.Entry(al).State = EntityState.Modified;
             db.SaveChanges();
             ActivityInfo   ai = db.ActivityInfoes.Where(x => x.activity_id == id && x.main_article == true).FirstOrDefault();
             ArticleVersion av = db.ArticleVersions.Where(x => x.article_id == ai.article_id && x.language_id == 1).FirstOrDefault();
             av.version_title = activity_name;
             db.SaveChanges();
             transaction.Commit();
             return(true);
         }
         catch (Exception)
         {
             transaction.Rollback();
             return(false);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Возвращает версию статьи
        /// </summary>
        /// <param name="id">ID версии</param>
        /// <param name="articleId">ID статьи (параметр необязательный, необходимо передавать только, если версия - текущая</param>
        /// <returns>информация о версии статьи</returns>
        internal static ArticleVersion GetById(int id, int articleId = 0)
        {
            ArticleVersion articleVersion;

            if (id == ArticleVersion.CurrentVersionId)
            {
                if (articleId == 0)
                {
                    throw new Exception("Article id is not specified!");
                }

                var article = ArticleRepository.GetById(articleId);
                articleVersion = new ArticleVersion
                {
                    ArticleId          = articleId,
                    Id                 = id,
                    Modified           = article.Modified,
                    LastModifiedBy     = article.LastModifiedBy,
                    LastModifiedByUser = article.LastModifiedByUser,
                    Article            = article
                };
            }
            else
            {
                var articleVersionDal = QPContext.EFContext.ArticleVersionSet.Include(n => n.LastModifiedByUser).SingleOrDefault(n => n.Id == id);
                articleVersion = MapperFacade.ArticleVersionMapper.GetBizObject(articleVersionDal);
                if (articleVersion != null)
                {
                    articleVersion.Article = ArticleRepository.GetById(articleVersion.ArticleId);
                }
            }

            return(articleVersion);
        }
Esempio n. 4
0
        public IHttpActionResult PutArticleVersion(int id, ArticleVersion articleVersion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != articleVersion.Id)
            {
                return(BadRequest());
            }

            db.Entry(articleVersion).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleVersionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
 public void cloneContent(cloneBase obj, ArticleVersion av_new, int activity_id)
 {
     if (obj.content != null)
     {
         cloneKP(obj, obj.content.Contains("KP"), activity_id);
         cloneDTC(obj, obj.content.Contains("DTC"), activity_id);
         cloneND(obj, obj.content.Contains("ND"), activity_id, av_new);
         cloneTD(obj, obj.content.Contains("TD"), activity_id);
     }
 }
Esempio n. 6
0
        public IHttpActionResult GetArticleVersion(int id)
        {
            ArticleVersion articleVersion = db.ArticleVersions.Find(id);

            if (articleVersion == null)
            {
                return(NotFound());
            }

            return(Ok(articleVersion));
        }
Esempio n. 7
0
 public bool clone(cloneBase obj)
 {
     using (DbContextTransaction transaction = db.Database.BeginTransaction())
     {
         try
         {
             ENTITIES.AcademicActivity aa = db.AcademicActivities.Add(new ENTITIES.AcademicActivity
             {
                 activity_type_id    = obj.activity_type_id,
                 activity_date_start = DateTime.ParseExact(obj.from, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                 activity_date_end   = DateTime.ParseExact(obj.to, "dd/MM/yyyy", CultureInfo.InvariantCulture)
             });
             db.SaveChanges();
             db.AcademicActivityLanguages.Add(new ENTITIES.AcademicActivityLanguage
             {
                 language_id = 1,
                 activity_id = aa.activity_id,
                 location    = obj.location
             });
             Article ar = db.Articles.Add(new ENTITIES.Article
             {
                 account_id        = 1,
                 article_status_id = 1,
                 need_approved     = false
             });
             db.SaveChanges();
             db.ActivityInfoes.Add(new ENTITIES.ActivityInfo
             {
                 activity_id  = aa.activity_id,
                 article_id   = ar.article_id,
                 main_article = true
             });
             ArticleVersion av_new = db.ArticleVersions.Add(new ENTITIES.ArticleVersion
             {
                 article_id      = ar.article_id,
                 publish_time    = DateTime.Now,
                 version_title   = obj.activity_name,
                 language_id     = 1,
                 article_content = ""
             });
             db.SaveChanges();
             int activity_id = aa.activity_id;
             cloneContent(obj, av_new, activity_id);
             transaction.Commit();
             return(true);
         }
         catch (Exception e)
         {
             transaction.Rollback();
             return(false);
         }
     }
 }
Esempio n. 8
0
        public IHttpActionResult PostArticleVersion(ArticleVersion articleVersion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ArticleVersions.Add(articleVersion);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = articleVersion.Id }, articleVersion));
        }
Esempio n. 9
0
 internal static MvcHtmlString VersionDateTime(
     this HtmlHelper source,
     string id,
     string value,
     string valueToMerge,
     ArticleViewType viewType
     ) => source.VersionText(
     id,
     viewType == ArticleViewType.PreviewVersion
         ? source.FormatAsDateTime(value)
         : ArticleVersion.Merge(source.FormatAsDateTime(value), source.FormatAsDateTime(valueToMerge))
     );
Esempio n. 10
0
        public static Article Restore(ArticleVersion version, bool?boundToExternal, bool disableNotifications)
        {
            if (!version.Article.IsArticleChangingActionsAllowed(boundToExternal))
            {
                throw new ActionNotAllowedException(ContentStrings.ArticleChangingIsProhibited);
            }

            var result = version.Article.Persist(disableNotifications);

            result.RestoreArticleFilesForVersion(version.Id);
            return(result);
        }
Esempio n. 11
0
        public IHttpActionResult PutArticle(int id, Article article)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != article.Id)
            {
                return(BadRequest());
            }

            try
            {
                var art = db.Articles.Where(x => x.Id == id).FirstOrDefault();
                if (art != null)
                {
                    if (art.Title != article.Title || art.ArticleText != article.ArticleText)
                    {
                        ArticleVersion artVers = new ArticleVersion()
                        {
                            ArticleId     = art.Id,
                            Title         = art.Title,
                            ArticleText   = art.ArticleText,
                            CreatorUserId = art.CreatorUserId,
                            VersionDate   = art.LastUpdate
                        };

                        db.ArticleVersions.Add(artVers);

                        art.Title       = article.Title;
                        art.ArticleText = article.ArticleText;
                        art.LastUpdate  = DateTime.Now;

                        db.SaveChanges();
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 12
0
        internal static MvcHtmlString VersionRelation(this HtmlHelper source, string id, string value, string valueToMerge, Field field, int articleId, ArticleViewType viewType)
        {
            if (viewType == ArticleViewType.CompareVersions)
            {
                var titles1 = field.GetRelatedTitles(value);
                var titles2 = field.GetRelatedTitles(valueToMerge);
                return(source.VersionText(id, ArticleVersion.MergeRelation(titles1, titles2)));
            }

            var titles = string.Join("<br />", field.GetRelatedTitles(value).Select(i => $"(#{i.Value}) - {i.Text}"));

            return(source.VersionText(id, titles));
        }
Esempio n. 13
0
        public IHttpActionResult DeleteArticleVersion(int id)
        {
            ArticleVersion articleVersion = db.ArticleVersions.Find(id);

            if (articleVersion == null)
            {
                return(NotFound());
            }

            db.ArticleVersions.Remove(articleVersion);
            db.SaveChanges();

            return(Ok(articleVersion));
        }
Esempio n. 14
0
        public static ArticleVersion GetMergedVersion(int[] ids, int parentId)
        {
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }
            if (ids.Length != 2)
            {
                throw new ArgumentException("Wrong ids length");
            }

            var result   = GetOrderedIds(ids);
            var version1 = ArticleVersionRepository.GetById(result.Item1, parentId);

            if (version1 == null)
            {
                throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFoundForArticle, result.Item1, parentId));
            }

            ArticleVersion version2;

            if (result.Item2 == ArticleVersion.CurrentVersionId)
            {
                var parent = ArticleRepository.GetById(parentId);
                if (parent == null)
                {
                    throw new Exception(string.Format(ArticleStrings.ArticleNotFound, parentId));
                }

                version2 = new ArticleVersion {
                    ArticleId = parent.Id, Article = parent, Id = ArticleVersion.CurrentVersionId, Modified = parent.Modified, LastModifiedBy = parent.LastModifiedBy, LastModifiedByUser = parent.LastModifiedByUser
                };
            }
            else
            {
                version2 = ArticleVersionRepository.GetById(result.Item2, parentId);
                if (version2 == null)
                {
                    throw new Exception(string.Format(ArticleStrings.ArticleVersionNotFoundForArticle, result.Item2, parentId));
                }
            }

            version1.MergeToVersion(version2);
            version1.Article.ViewType = ArticleViewType.CompareVersions;
            version1.AggregatedArticles.ForEach(x => { x.ViewType = ArticleViewType.CompareVersions; });
            return(version1);
        }
Esempio n. 15
0
 public void cloneND(cloneBase obj, bool start, int activity_id, ArticleVersion av_new)
 {
     if (start)
     {
         List <int>          ids_article   = new List <int>();
         List <ActivityInfo> activityInfos = db.ActivityInfoes.Where(x => x.activity_id == obj.id && x.main_article == false).ToList();
         foreach (ActivityInfo info in activityInfos)
         {
             Article a = db.Articles.Add(new Article
             {
                 account_id        = 1,
                 article_status_id = 1,
                 need_approved     = false
             });
             db.SaveChanges();
             List <ArticleVersion> old = db.ArticleVersions.Where(x => x.article_id == info.article_id).ToList();
             foreach (ArticleVersion o in old)
             {
                 db.ArticleVersions.Add(new ArticleVersion
                 {
                     article_id      = a.article_id,
                     publish_time    = DateTime.Now,
                     version_title   = o.version_title,
                     language_id     = o.language_id,
                     article_content = o.article_content
                 });
             }
             db.SaveChanges();
             db.ActivityInfoes.Add(new ActivityInfo
             {
                 article_id   = a.article_id,
                 activity_id  = activity_id,
                 main_article = info.main_article
             });
             db.SaveChanges();
         }
         ActivityInfo   ai = db.ActivityInfoes.Where(x => x.activity_id == obj.id && x.main_article == true).FirstOrDefault();
         ArticleVersion av = db.ArticleVersions.Where(x => x.article_id == ai.article_id).FirstOrDefault();
         av_new.article_content = av.article_content;
         db.Entry(av_new).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 16
0
        public ActionResult Edit(EditArticleViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var article = _articleRepository.Get(vm.Id);

                //Create a version
                var newVersion = new ArticleVersion
                {
                    ArticleId       = article.Id,
                    Version         = article.Version,
                    CreatedByUserId = WebUser.Id,
                    Content         = JsonConvert.SerializeObject(article)
                };

                _articleVersionRepository.Create(newVersion);
                _unitOfWork.Commit();

                article.Title           = vm.Title;
                article.ArticleVersion  = vm.ArticleVersion;
                article.IsPublic        = vm.IsPublic;
                article.Summary         = vm.Summary;
                article.Content         = vm.Content;
                article.KeyWords        = vm.KeyWords;
                article.IsFeatured      = vm.IsFeatured;
                article.State           = vm.State;
                article.CategoryId      = vm.CategoryId;
                article.Version         = article.Version + 1;
                article.UpdatedByUserId = WebUser.Id;

                _articleRepository.Update(article);
                _unitOfWork.Commit();

                return(RedirectToAction("Manage"));
            }

            // Not using SelectList as we are getting an exception for the Html Content like potentially dangerours
            ViewBag.CategoryId = new SelectList(_categoryRepository.GetAll(), "Id", "Title", vm.CategoryId);
            return(View(vm));
        }
Esempio n. 17
0
        private static MvcHtmlString VersionClassifierField(this HtmlHelper source, string name, string value, Field field, Article article, ArticleVersion version = null, bool forceReadOnly = true, string valueToMerge = null)
        {
            var name1 = version?.GetAggregatedContent(value)?.Name;

            if (!StringComparer.InvariantCultureIgnoreCase.Equals(value, valueToMerge) && article.ViewType == ArticleViewType.CompareVersions)
            {
                var name2       = version?.VersionToMerge.GetAggregatedContent(valueToMerge)?.Name;
                var mergedValue = ArticleVersion.Merge(Formatter.ProtectHtml(name1), Formatter.ProtectHtml(name2));
                return(source.VersionText(name, mergedValue));
            }

            Article aggregatedArticle = null;
            var     classifierValue   = Converter.ToInt32(value, 0);

            if (article.ViewType != ArticleViewType.Virtual)
            {
                aggregatedArticle = version?.AggregatedArticles.SingleOrDefault(n => n.ContentId == classifierValue);
            }

            var sb = new StringBuilder(source.BeginClassifierFieldComponent(name, value, field, article, aggregatedArticle, out var _));

            if (forceReadOnly)
            {
                sb.Append(source.VersionText(name, name1));
            }
            else
            {
                var contentListHtmlAttrs = new Dictionary <string, object> {
                    { "class", "dropDownList classifierContentList" }
                };
                sb.Append(source.DropDownList(name, source.List(ArticleViewModel.GetAggregatableContentsForClassifier(field, value)), FieldStrings.SelectContent, contentListHtmlAttrs).ToHtmlString());
            }

            sb.Append(EndClassifierFieldComponent());
            return(MvcHtmlString.Create(sb.ToString()));
        }
Esempio n. 18
0
        internal static IHtmlContent VersionFile(this IHtmlHelper source, string id, string value, Field field, ArticleVersion version, ArticleViewType viewType)
        {
            if (viewType == ArticleViewType.CompareVersions)
            {
                return(source.VersionText(id, value));
            }

            var tb = source.FileWrapper(id, null, field, version.Id, version, true, false);

            tb.InnerHtml.AppendHtml(source.VersionText(id, value));

            if (field.TypeId == FieldTypeCodes.Image)
            {
                tb.InnerHtml.AppendHtml(source.ImagePreview(id));
            }

            tb.InnerHtml.AppendHtml(source.FileDownload(id));

            return(tb);
        }
Esempio n. 19
0
        internal static MvcHtmlString VersionTime(this HtmlHelper source, string id, string value, string valueToMerge, ArticleViewType viewType)
        {
            var resultValue = viewType == ArticleViewType.PreviewVersion ? source.FormatAsTime(value) : ArticleVersion.Merge(source.FormatAsTime(value), source.FormatAsTime(valueToMerge));

            return(source.VersionText(id, resultValue));
        }
Esempio n. 20
0
 public static List <ArticleVersion> List(int articleId, ListCommand command)
 {
     command.SortExpression = ArticleVersion.TranslateSortExpression(command.SortExpression);
     return(ArticleVersionRepository.GetList(articleId, command));
 }
Esempio n. 21
0
        internal static MvcHtmlString VersionFile(this HtmlHelper source, string id, string value, Field field, ArticleVersion version, ArticleViewType viewType)
        {
            if (viewType == ArticleViewType.CompareVersions)
            {
                return(source.VersionText(id, value));
            }

            var sb = new StringBuilder();

            sb.Append(source.VersionText(id, value));
            if (field.TypeId == FieldTypeCodes.Image)
            {
                sb.Append(source.ImagePreview(id));
            }

            sb.Append(source.FileDownload(id));
            var tb = source.FileWrapper(id, null, field, version.Id, version, true, false);

            tb.InnerHtml = sb.ToString();

            return(MvcHtmlString.Create(tb.ToString()));
        }