Example #1
0
        public Article GetArticleById(int articleId)
        {
            try
            {
                var article = new Article();
                article = articleRepository.GetById(articleId);
                article.Reviewers = articleRepository.GetReviewers(articleId);
                return article;
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }

            return null;
        }
		public int Insert(Article item)
		{
			using (var conn = db.GetOpenConnection())
			{
				using (var tran = conn.BeginTransaction())
				{
					try
					{
						string sql = @" INSERT INTO Article(UserID, Title, [Description], CategoryID, Keywords, FilePath, Comments)
								VALUES (@UserID, @Title, @Description, @CategoryID, @Keywords, @FilePath, @Comments);
								SELECT CAST(SCOPE_IDENTITY() AS INT);";

						int articleId = conn.Query<int>(sql, item, tran).Single();
						if (articleId > 0)
						{
							foreach (var author in item.Authors)
							{
								if (!author.HasValues)
									continue;
								author.ArticleID = articleId;
								conn.Execute(@" INSERT INTO ArticleAuthor(ArticleID, FirstName, LastName, Email, DegreeID)
										VALUES(@ArticleID, @FirstName, @LastName, @Email, @DegreeID)",
												new { author.ArticleID, author.FirstName, author.LastName, author.Email, author.DegreeID }, tran);
							}
						}

						tran.Commit();
						return articleId;
					}
					catch(Exception)
					{
						tran.Rollback();
						return 0;
					}
				}
			}             
		}
		public void Update(Article item)
		{
			using (var conn = db.GetOpenConnection())
			{
				using (var tran = conn.BeginTransaction())
				{
					try
					{
						var parameters = new DynamicParameters(item);

						string sql = @" UPDATE [Article]
								SET [UserID] = @UserID
									,[Title] = @Title
									,[Description] = @Description
									,[CategoryID] = @CategoryID
									,[ArticleStatusID] = @ArticleStatusID
									,[Keywords] = @Keywords
									,[FilePath] = @FilePath
									,[ReviewersFilePath] = @ReviewersFilePath
									,[Comments] = @Comments
									,[FileLinkGuid] = @FileLinkGuid
									,[FileLinkExpirationDate] = @FileLinkExpirationDate
									,[CreationDateUtc] = @CreationDateUtc
									,UpdatedDateUtc = @UpdatedDateUtc
									,UpdatedByUserID = @UpdatedByUserID
								WHERE ArticleID = @ArticleID";

						conn.Execute(sql, parameters, tran);

						conn.Execute("DELETE FROM ArticleAuthor WHERE ArticleID = @ArticleAuthorID",
							new { ArticleAuthorID = item.ArticleID }, tran);
							
						foreach(var author in item.Authors)
						{
							author.ArticleID = item.ArticleID;
							conn.Execute(@" INSERT INTO ArticleAuthor(ArticleID, FirstName, LastName, Email, DegreeID)
											VALUES(@ArticleID, @FirstName, @LastName, @Email, @DegreeID)",
											new { author.ArticleID, author.FirstName, author.LastName, author.Email, author.DegreeID }, tran);
						}

						tran.Commit();
					}
					catch(Exception)
					{
						tran.Rollback();
						throw;
					}
				}             
			}
		}
Example #4
0
        public CallResult SaveArticle(Article article, string directoryPath)
        {
            try
            {
                article.ArticleID = articleRepository.Insert(article);
                if (article.ArticleID != 0)
                {
                    string filePath = UploadArticleDocument(article.FileStream, article.FilePath, article.ArticleID, directoryPath);
                    articleRepository.UpdateFilePath(article.ArticleID, filePath);
                    result.SetSuccess("Su artículo ha sido enviado.");
                }
                else
                    result.SetError();
            }
            catch(Exception e)
            {
                Logger.Log(e);
                result.SetError();
            }

            return result;
        }
Example #5
0
        public CallResult UpdateArticle(Article article, int? userId = null, string destinationPath = null)
        {
            try
            {
                Article item;
                if (userId.HasValue)
                    item = GetArticleByUserId(article.ArticleID, userId.Value);
                else
                    item = GetArticleById(article.ArticleID);

                if(item != null)
                {
                    if(article.FilePath != null && article.FileStream != null)
                    {
                        item.FilePath = UploadArticleDocument(article.FileStream, article.FilePath, article.ArticleID, destinationPath);
                        if (item.FilePath == null)
                        {
                            result.SetWarning("No se pudo actualizar el artículo.");
                            return result;
                        }
                    }

                    item.Title = article.Title;
                    item.Description = article.Description;
                    item.Keywords = article.Keywords;
                    item.CategoryID = article.CategoryID;
                    item.Comments = article.Comments;
                    item.Authors = article.Authors;
                    item.UpdatedByUserID = article.UpdatedByUserID;

                    articleRepository.Update(item);
                    if(article.FilePath != null)
                        DeleteArticleDocument(article.ArticleID, article.FilePath, destinationPath);
                    result.SetSuccess("Se actualizó el artículo.");
                }
                else
                    result.SetWarning("No se pudo actualizar el artículo.");
            }
            catch (Exception e)
            {
                Logger.Log(e);
                result.SetError();
            }

            return result;
        }