Пример #1
0
 /// <summary>
 /// Сохраняет в БД
 /// </summary>
 /// <param name="apod"></param>
 public static void Save(NasaAPOD apod)
 {
     using (var db = new NasaApodContext.NasaAPODContext())
     {
         db.NasaAPODs.Add(apod);
         db.SaveChanges();
     }
 }
Пример #2
0
        /// <summary>
        /// Сохраняет объект
        /// </summary>
        /// <param name="modifyApod"></param>
        public static void Update(NasaAPOD modifyApod)
        {
            using (var db = new NasaApodContext.NasaAPODContext())
            {
                var original = db.NasaAPODs.Find(modifyApod.Id);

                if (original != null)
                {
                    db.Entry(original).CurrentValues.SetValues(modifyApod);
                    db.SaveChanges();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Отдает комментарии к публикации
        /// </summary>
        /// <param name="apod"></param>
        /// <returns></returns>
        public static int GetCountComments(NasaAPOD apod, bool isPublic = true)
        {
            var count = 0;

            if (apod == null)
            {
                return(0);
            }
            using (var db = new CommentsContext())
            {
                count = db.Comments.Count(o => o.Post_Id == apod.Id && o.IsPublic == isPublic);
            }
            return(count);
        }
Пример #4
0
        /// <summary>
        /// Отдает комментарии к публикации
        /// </summary>
        /// <param name="apod"></param>
        /// <returns></returns>
        public static List <Comments> GetListComments(NasaAPOD apod, bool isPublic = true)
        {
            var comments = new List <Comments>();

            if (apod == null)
            {
                return(comments);
            }
            using (var db = new CommentsContext())
            {
                comments = db.Comments.Where(o => o.Post_Id == apod.Id && o.IsPublic == isPublic).OrderBy(o => o.PublicateDate).ToList();
            }
            return(comments);
        }
Пример #5
0
        /// <summary>
        /// Создает из Json объекта NASAApod
        /// </summary>
        /// <param name="apod"></param>
        /// <param name="explanationRu"></param>
        /// <returns></returns>
        private static NasaAPOD Create(answerNasaAPI apod, string explanationRu)
        {
            NasaAPOD nasaApod = new NasaAPOD
            {
                Id            = Convert.ToInt32(apod.date.Replace("-", "")),
                Explanation   = apod.explanation,
                ExplanationRu = explanationRu,
                HDUrl         = apod.hdur,
                Title         = apod.title,
                Url           = apod.url,
                MediaType     = apod.media_type,
                ViewsCount    = 0
            };

            Save(nasaApod);
            return(nasaApod);
        }
Пример #6
0
        private void AddPostComments(NasaAPOD apod)
        {
            var comments = MainApodObjectOperations.GetListComments(apod);

            infobar.Controls.Clear();
            var commentsCount  = comments.Count;
            var HTMLPoststring = string.Format("<span class=\"tags\"> Количество просмотров: {0}</span>" +
                                               "<span class=\"comments\">({1}) Комментариев</span>",
                                               apod.ViewsCount,
                                               commentsCount);

            infobar.Controls.Add(new LiteralControl(HTMLPoststring));
            if (commentsCount != 0)
            {
                CommentsPosts.Controls.Clear();
                AddCommets(comments);
            }
        }
Пример #7
0
 /// <summary>
 /// Скачивает и сохраняет новый объект
 /// </summary>
 /// <param name="date"></param>
 /// <returns></returns>
 public static NasaAPOD AddNewNasaApod(DateTime date)
 {
     try
     {
         answerNasaAPI newNasaApod   = DownlandNasaApod(date);
         var           explanationRu = TranslateExplanation(newNasaApod.explanation);
         if (string.IsNullOrEmpty(newNasaApod.date) || string.IsNullOrEmpty(newNasaApod.url) ||
             string.IsNullOrEmpty(explanationRu))
         {
             return(null);
         }
         NasaAPOD nasaApod = Create(newNasaApod, explanationRu);
         return(nasaApod);
     }
     catch (Exception)
     {
         return(null);
     }
 }