Ejemplo n.º 1
0
        public bool Insert(ArticleLanguage articlelanguage)
        {
            int autonumber = 0;
            ArticleLanguageDAC articlelanguageComponent = new ArticleLanguageDAC();
            bool endedSuccessfuly = articlelanguageComponent.InsertNewArticleLanguage(ref autonumber, articlelanguage.ArticleId, articlelanguage.LanguageId, articlelanguage.ArticleName, articlelanguage.ArticleContent, articlelanguage.ArticleAttachment, articlelanguage.AuthorAlias, articlelanguage.ArticleAlias, articlelanguage.PostDate, articlelanguage.PublishStartDate, articlelanguage.PublishEndDate, articlelanguage.RevisionDate, articlelanguage.ModifiedDate, articlelanguage.ArticleSummary);

            if (endedSuccessfuly)
            {
                articlelanguage.ArticleLanguageId = autonumber;
            }
            return(endedSuccessfuly);
        }
        public IHttpActionResult Articles(ArticleLanguage language)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Passed information isn't valid."));
                }

                var src = Mapper.MapSource(language);
                if (src != null)
                {
                    var da   = new DataAccess();
                    var arts = da.GetArticles(src);
                    if (arts == null)
                    {
                        return(NotFound());
                    }

                    // Let's convert the article objects
                    var articles = Mapper.MapArticle(arts);

                    if (articles == null)
                    {
                        throw new NotImplementedException();
                    }

                    return(Ok(articles));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Attempt to get articles from language " + language.Language + " failed: " + ex.Message);
                return(BadRequest("Something went wrong while saving comment."));
            }
        }
Ejemplo n.º 3
0
        // Map ArticleLanguage object to DAL.Source object
        public static Source MapSource(ArticleLanguage lang)
        {
            try
            {
                if (lang == null)
                {
                    throw new NotImplementedException();
                }

                var src = new Source()
                {
                    Language = lang.Language
                };

                return(src);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Attempt to map ArticleLanguage " + lang.Language + " to Source failed: " + ex.Message);
                return(null);
            }
        }
Ejemplo n.º 4
0
        public List <ArticleLanguage> GetAllByArticleId(int ArticleId)
        {
            ArticleLanguageDAC     _articleLanguageComponent = new ArticleLanguageDAC();
            IDataReader            reader = _articleLanguageComponent.GetAllArticleLanguage("ArticleId = " + ArticleId).CreateDataReader();
            List <ArticleLanguage> _articleLanguageList = new List <ArticleLanguage>();

            while (reader.Read())
            {
                if (_articleLanguageList == null)
                {
                    _articleLanguageList = new List <ArticleLanguage>();
                }
                ArticleLanguage _articleLanguage = new ArticleLanguage();
                if (reader["ArticleLanguageId"] != DBNull.Value)
                {
                    _articleLanguage.ArticleLanguageId = Convert.ToInt32(reader["ArticleLanguageId"]);
                }
                if (reader["ArticleId"] != DBNull.Value)
                {
                    _articleLanguage.ArticleId = Convert.ToInt32(reader["ArticleId"]);
                }
                if (reader["LanguageId"] != DBNull.Value)
                {
                    _articleLanguage.LanguageId = Convert.ToInt32(reader["LanguageId"]);
                }
                if (reader["ArticleName"] != DBNull.Value)
                {
                    _articleLanguage.ArticleName = Convert.ToString(reader["ArticleName"]);
                }
                if (reader["ArticleContent"] != DBNull.Value)
                {
                    _articleLanguage.ArticleContent = Convert.ToString(reader["ArticleContent"]);
                }
                if (reader["ArticleAttachment"] != DBNull.Value)
                {
                    _articleLanguage.ArticleAttachment = Convert.ToString(reader["ArticleAttachment"]);
                }
                if (reader["AuthorAlias"] != DBNull.Value)
                {
                    _articleLanguage.AuthorAlias = Convert.ToString(reader["AuthorAlias"]);
                }
                if (reader["ArticleAlias"] != DBNull.Value)
                {
                    _articleLanguage.ArticleAlias = Convert.ToString(reader["ArticleAlias"]);
                }
                if (reader["PostDate"] != DBNull.Value)
                {
                    _articleLanguage.PostDate = Convert.ToDateTime(reader["PostDate"]);
                }
                if (reader["PublishStartDate"] != DBNull.Value)
                {
                    _articleLanguage.PublishStartDate = Convert.ToDateTime(reader["PublishStartDate"]);
                }
                if (reader["PublishEndDate"] != DBNull.Value)
                {
                    _articleLanguage.PublishEndDate = Convert.ToDateTime(reader["PublishEndDate"]);
                }
                if (reader["RevisionDate"] != DBNull.Value)
                {
                    _articleLanguage.RevisionDate = Convert.ToDateTime(reader["RevisionDate"]);
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _articleLanguage.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                if (reader["ArticleSummary"] != DBNull.Value)
                {
                    _articleLanguage.ArticleSummary = Convert.ToString(reader["ArticleSummary"]);
                }
                _articleLanguage.NewRecord = false;
                _articleLanguageList.Add(_articleLanguage);
            }
            reader.Close();
            return(_articleLanguageList);
        }
Ejemplo n.º 5
0
        public ArticleLanguage GetByArticleIDlanguageId(int ArticleId, int LanguageId)
        {
            ArticleLanguageDAC _articleLanguageComponent = new ArticleLanguageDAC();
            IDataReader        reader           = _articleLanguageComponent.GetByIDArticleIdLanguageIdArticlelanguage(ArticleId, LanguageId);
            ArticleLanguage    _articleLanguage = null;

            while (reader.Read())
            {
                _articleLanguage = new ArticleLanguage();
                if (reader["ArticleLanguageId"] != DBNull.Value)
                {
                    _articleLanguage.ArticleLanguageId = Convert.ToInt32(reader["ArticleLanguageId"]);
                }
                if (reader["ArticleId"] != DBNull.Value)
                {
                    _articleLanguage.ArticleId = Convert.ToInt32(reader["ArticleId"]);
                }
                if (reader["LanguageId"] != DBNull.Value)
                {
                    _articleLanguage.LanguageId = Convert.ToInt32(reader["LanguageId"]);
                }
                if (reader["ArticleName"] != DBNull.Value)
                {
                    _articleLanguage.ArticleName = Convert.ToString(reader["ArticleName"]);
                }
                if (reader["ArticleContent"] != DBNull.Value)
                {
                    _articleLanguage.ArticleContent = Convert.ToString(reader["ArticleContent"]);
                }
                if (reader["ArticleAttachment"] != DBNull.Value)
                {
                    _articleLanguage.ArticleAttachment = Convert.ToString(reader["ArticleAttachment"]);
                }
                if (reader["AuthorAlias"] != DBNull.Value)
                {
                    _articleLanguage.AuthorAlias = Convert.ToString(reader["AuthorAlias"]);
                }
                if (reader["ArticleAlias"] != DBNull.Value)
                {
                    _articleLanguage.ArticleAlias = Convert.ToString(reader["ArticleAlias"]);
                }
                if (reader["PostDate"] != DBNull.Value)
                {
                    _articleLanguage.PostDate = Convert.ToDateTime(reader["PostDate"]);
                }
                if (reader["PublishStartDate"] != DBNull.Value)
                {
                    _articleLanguage.PublishStartDate = Convert.ToDateTime(reader["PublishStartDate"]);
                }
                if (reader["PublishEndDate"] != DBNull.Value)
                {
                    _articleLanguage.PublishEndDate = Convert.ToDateTime(reader["PublishEndDate"]);
                }
                if (reader["RevisionDate"] != DBNull.Value)
                {
                    _articleLanguage.RevisionDate = Convert.ToDateTime(reader["RevisionDate"]);
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _articleLanguage.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                if (reader["ArticleSummary"] != DBNull.Value)
                {
                    _articleLanguage.ArticleSummary = Convert.ToString(reader["ArticleSummary"]);
                }
                _articleLanguage.NewRecord = false;
            }
            reader.Close();
            return(_articleLanguage);
        }
Ejemplo n.º 6
0
        public bool Update(ArticleLanguage articlelanguage, int old_articleLanguageId)
        {
            ArticleLanguageDAC articlelanguageComponent = new ArticleLanguageDAC();

            return(articlelanguageComponent.UpdateArticleLanguage(articlelanguage.ArticleId, articlelanguage.LanguageId, articlelanguage.ArticleName, articlelanguage.ArticleContent, articlelanguage.ArticleAttachment, articlelanguage.AuthorAlias, articlelanguage.ArticleAlias, articlelanguage.PostDate, articlelanguage.PublishStartDate, articlelanguage.PublishEndDate, articlelanguage.RevisionDate, articlelanguage.ModifiedDate, articlelanguage.ArticleSummary, old_articleLanguageId));
        }
        private HttpRequestMessage CreateSearchRequestToService(Search search)
        {
            try
            {
                HttpRequestMessage requestMessage = CreateRequestToService(HttpMethod.Post, "api/Data/" + search.Criteria);
                if (search.Criteria == "Title")
                {
                    var at = new ArticleTitle()
                    {
                        Title = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleTitle>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Topic")
                {
                    var at = new ArticleTopic()
                    {
                        Topic = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleTopic>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Source")
                {
                    var at = new ArticleSource()
                    {
                        Name = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleSource>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Country")
                {
                    var at = new ArticleCountry()
                    {
                        Country = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleCountry>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Language")
                {
                    var at = new ArticleLanguage()
                    {
                        Language = search.SearchString
                    };
                    requestMessage.Content = new ObjectContent <ArticleLanguage>(at, new JsonMediaTypeFormatter());
                }
                else if (search.Criteria == "Date")
                {
                    var at = new ArticlePulished()
                    {
                        PublishedDate = Convert.ToDateTime(search.SearchString)
                    };
                    requestMessage.Content = new ObjectContent <ArticlePulished>(at, new JsonMediaTypeFormatter());
                }

                return(requestMessage);
            }
            catch (Exception ex)
            {
                // log the error here
                logger.Error(ex.Message);
                return(null);
            }
        }