Exemple #1
0
        public void SaveCommentRecords(AdminNewsViewModel model)
        {
            if (model.Id > 0)
            {
                News_Comments _skills = _db.News_Comments.Where(x => x.Id == model.Id).FirstOrDefault();
                _skills.NewsId               = model.NewsId;
                _skills.Archived             = false;
                _skills.UserIDLastModifiedBy = model.CurrentUserId;
                _skills.Comments             = model.Comments;
                _skills.LastModified         = DateTime.Now;
                _db.SaveChanges();
            }
            else
            {
                News_Comments _skills = new News_Comments();
                _skills.NewsId          = model.NewsId;
                _skills.Archived        = false;
                _skills.UserIDCreatedBy = model.CurrentUserId;
                _skills.Comments        = model.Comments;
                _skills.CreatedDate     = DateTime.Now;
                _db.News_Comments.Add(_skills);
                _db.SaveChanges();

                if (model.NotifyEmployeeViaEmail == true)
                {
                    Mail.NewsCommentNotificationSendEmailAsync(model.NewsId, model.Comments);
                }
            }
        }
Exemple #2
0
        public void Deletecommentrecord(int Id, int Users)
        {
            AdminNewsViewModel model   = new AdminNewsViewModel();
            News_Comments      _skills = _db.News_Comments.Where(x => x.Id == Id).FirstOrDefault();

            _skills.Archived             = true;
            _skills.LastModified         = DateTime.Now;
            _skills.UserIDLastModifiedBy = Users;
            _db.SaveChanges();
        }
 public ActionResult AddComments(News_Comments comment)
 {
     try
     {
         if (ModelState.IsValid)
         {
             database.News_Comments.Add(new News_Comments
             {
                 NewsID    = comment.NewsID,
                 ParentID  = comment.ParentID,
                 Name      = comment.Name,
                 Text      = comment.Text,
                 Email     = comment.Email,
                 IsApprove = false,
                 Date      = DateTime.Now,
             });
             database.SaveChanges();
             return(Json(new { state = "success", msg = "نظر شما پس از تایید، نمایش داده می شود." }));
         }
         else
         {
             var errorList = from x in ModelState.Keys
                             where ModelState[x].Errors.Count > 0
                             select new
             {
                 key    = x,
                 errors = ModelState[x].Errors.
                          Select(y => y.ErrorMessage).
                          ToArray()
             };
             return(Json(new { state = "warning", msg = errorList.Select(q => q.errors).ToArray()[0] }));
         }
     }
     catch (Exception e)
     {
         return(Json(new { state = "error", msg = e.Message }));
     }
 }
        private async Task getNewsInfo(string last_news_id)
        {
            isLoading            = true;
            loadingbar.IsRunning = true;
            temp_news_id         = last_news_id;

            using (var cl = new HttpClient())
            {
                var formcontent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>(Constants.LAST_NEWS_ID, last_news_id)
                });

                try
                {
                    var request = await cl.PostAsync(Constants.SERVER_GET_NEWS_URL, formcontent);

                    request.EnsureSuccessStatusCode();
                    var response = await request.Content.ReadAsStringAsync();

                    ResponseMsg resultMsg = JsonConvert.DeserializeObject <ResponseMsg>(response);

                    if (resultMsg.resp.Equals("success"))
                    {
                        isLoading            = false;
                        loadingbar.IsRunning = false;

                        ResponseData resultData = JsonConvert.DeserializeObject <ResponseData>(response);
                        var          news_num   = resultData.news_data.Length;

                        if (news_num != 0)
                        {
                            App.last_news_id = resultData.news_data[news_num - 1].news_id;

                            for (int i = 0; i < news_num; i++)
                            {
                                News tmpnews = new News();

                                string thumbnail_img_header   = null;
                                string thumbnail_img          = null;
                                string first_comment_contents = null;
                                string first_img   = null;
                                string first_name  = null;
                                string second_img  = null;
                                string second_name = null;
                                string third_img   = null;
                                string third_name  = null;
                                int    thumbnail_img_header_height = 0;
                                string main_imgNews_url            = null;

                                string news_img = resultData.news_data[i].news_image_url;
                                if (news_img.Length >= 4 && (string.Equals(news_img.Substring(news_img.Length - 4), ".jpg") || string.Equals(news_img.Substring(news_img.Length - 4), ".png") || string.Equals(news_img.Substring(news_img.Length - 5), ".jpeg")))
                                {
                                    main_imgNews_url = resultData.news_data[i].news_image_url;

                                    if (i == 0 && string.IsNullOrEmpty(last_news_id))
                                    {
                                        thumbnail_img_header        = resultData.news_data[i].news_image_url;
                                        thumbnail_img_header_height = 200;
                                    }
                                    else
                                    {
                                        thumbnail_img = resultData.news_data[i].news_image_url;
                                    }
                                }
                                else
                                {
                                    main_imgNews_url = "noimage.png";
                                    if (i == 0)
                                    {
                                        thumbnail_img_header        = "noimage.png";
                                        thumbnail_img_header_height = 200;
                                    }
                                    else
                                    {
                                        thumbnail_img = "noimage.png";
                                    }
                                }

                                if (resultData.news_data[i].news_comment_data.Length != 0)
                                {
                                    first_comment_contents = resultData.news_data[i].news_comment_data[0].news_comment_contents;

                                    if (resultData.news_data[i].news_comment_data.Length == 1)
                                    {
                                        first_img  = resultData.news_data[i].news_comment_data[0].news_comment_writer_image;
                                        first_name = resultData.news_data[i].news_comment_data[0].news_comment_writer_name;

                                        if (string.IsNullOrEmpty(first_img))
                                        {
                                            first_img = "imgUser.png";
                                        }
                                        else
                                        {
                                            if (first_img.Substring(0, 1) == "o")
                                            {
                                                first_img = Constants.IMAGE_UPLOAD_URL_PREFIX + first_img;
                                            }
                                            else if (first_img.Substring(0, 1) == "t")
                                            {
                                                first_img = Constants.IMAGE_UPLOAD_URL_PREFIX_TENANT + first_img;
                                            }
                                        }
                                    }
                                    else if (resultData.news_data[i].news_comment_data.Length == 2)
                                    {
                                        first_img   = resultData.news_data[i].news_comment_data[0].news_comment_writer_image;
                                        first_name  = resultData.news_data[i].news_comment_data[0].news_comment_writer_name;
                                        second_img  = resultData.news_data[i].news_comment_data[1].news_comment_writer_image;
                                        second_name = resultData.news_data[i].news_comment_data[1].news_comment_writer_name;
                                        if (string.IsNullOrEmpty(first_img))
                                        {
                                            first_img = "imgUser.png";
                                        }
                                        else
                                        {
                                            if (first_img.Substring(0, 1) == "o")
                                            {
                                                first_img = Constants.IMAGE_UPLOAD_URL_PREFIX + first_img;
                                            }
                                            else if (first_img.Substring(0, 1) == "t")
                                            {
                                                first_img = Constants.IMAGE_UPLOAD_URL_PREFIX_TENANT + first_img;
                                            }
                                        }
                                        if (string.IsNullOrEmpty(second_img))
                                        {
                                            second_img = "imgUser.png";
                                        }
                                        else
                                        {
                                            if (second_img.Substring(0, 1) == "o")
                                            {
                                                second_img = Constants.IMAGE_UPLOAD_URL_PREFIX + second_img;
                                            }
                                            else if (first_img.Substring(0, 1) == "t")
                                            {
                                                second_img = Constants.IMAGE_UPLOAD_URL_PREFIX_TENANT + second_img;
                                            }
                                        }
                                    }
                                    else if (resultData.news_data[i].news_comment_data.Length >= 3)
                                    {
                                        first_img   = resultData.news_data[i].news_comment_data[0].news_comment_writer_image;
                                        first_name  = resultData.news_data[i].news_comment_data[0].news_comment_writer_name;
                                        second_img  = resultData.news_data[i].news_comment_data[1].news_comment_writer_image;
                                        second_name = resultData.news_data[i].news_comment_data[1].news_comment_writer_name;
                                        third_img   = resultData.news_data[i].news_comment_data[2].news_comment_writer_image;
                                        third_name  = resultData.news_data[i].news_comment_data[2].news_comment_writer_name;
                                        if (string.IsNullOrEmpty(first_img))
                                        {
                                            first_img = "imgUser.png";
                                        }
                                        else
                                        {
                                            if (first_img.Substring(0, 1) == "o")
                                            {
                                                first_img = Constants.IMAGE_UPLOAD_URL_PREFIX + first_img;
                                            }
                                            else if (first_img.Substring(0, 1) == "t")
                                            {
                                                first_img = Constants.IMAGE_UPLOAD_URL_PREFIX_TENANT + first_img;
                                            }
                                        }
                                        if (string.IsNullOrEmpty(second_img))
                                        {
                                            second_img = "imgUser.png";
                                        }
                                        else
                                        {
                                            if (second_img.Substring(0, 1) == "o")
                                            {
                                                second_img = Constants.IMAGE_UPLOAD_URL_PREFIX + second_img;
                                            }
                                            else if (first_img.Substring(0, 1) == "t")
                                            {
                                                second_img = Constants.IMAGE_UPLOAD_URL_PREFIX_TENANT + second_img;
                                            }
                                        }
                                        if (string.IsNullOrEmpty(third_img))
                                        {
                                            third_img = "imgUser.png";
                                        }
                                        else
                                        {
                                            if (third_img.Substring(0, 1) == "o")
                                            {
                                                third_img = Constants.IMAGE_UPLOAD_URL_PREFIX + third_img;
                                            }
                                            else if (first_img.Substring(0, 1) == "t")
                                            {
                                                third_img = Constants.IMAGE_UPLOAD_URL_PREFIX_TENANT + third_img;
                                            }
                                        }
                                    }
                                }

                                tmpnews.news_id = resultData.news_data[i].news_id;
                                tmpnews.news_image_url_header   = thumbnail_img_header;
                                tmpnews.img_header_height       = thumbnail_img_header_height;
                                tmpnews.news_image_url_contents = thumbnail_img;
                                tmpnews.news_image_url          = main_imgNews_url;
                                tmpnews.news_category           = resultData.news_data[i].news_category;
                                tmpnews.news_title     = resultData.news_data[i].news_title;
                                tmpnews.news_date      = resultData.news_data[i].news_date;
                                tmpnews.news_source    = resultData.news_data[i].news_source;
                                tmpnews.writer_name    = resultData.news_data[i].news_writer_name;
                                tmpnews.writer_profile = resultData.news_data[i].news_writer_profile;
                                tmpnews.news_url       = resultData.news_data[i].news_url;
                                tmpnews.news_contents  = resultData.news_data[i].news_contents;

                                var favorite_tapped_news = await App.Favorite_News_Data.GetSelectedNewsAsync(resultData.news_data[i].news_id);

                                if (favorite_tapped_news != null)
                                {
                                    tmpnews.imgfavorite = "favorite.png";
                                }
                                else
                                {
                                    tmpnews.imgfavorite = "infavorite.png";
                                }

                                tmpnews.comment_count          = resultData.news_data[i].news_comment_data.Count();
                                tmpnews.brief_comment          = first_comment_contents;
                                tmpnews.first_commenter_image  = first_img;
                                tmpnews.first_commenter_name   = first_name;
                                tmpnews.second_commenter_image = second_img;
                                tmpnews.second_commenter_name  = second_name;
                                tmpnews.third_commenter_image  = third_img;
                                tmpnews.third_commenter_name   = third_name;

                                tmpnews.news_comment_data = new List <News_Comments>();
                                if (tmpnews.comment_count != 0)
                                {
                                    for (int j = 0; j < tmpnews.comment_count; j++)
                                    {
                                        News_Comments tmp_news_comments = new News_Comments();

                                        tmp_news_comments.news_comment_id             = resultData.news_data[i].news_comment_data[j].news_comment_id;
                                        tmp_news_comments.news_comment_writer_image   = resultData.news_data[i].news_comment_data[j].news_comment_writer_image;
                                        tmp_news_comments.news_comment_writer_name    = resultData.news_data[i].news_comment_data[j].news_comment_writer_name;
                                        tmp_news_comments.news_comment_writer_profile = resultData.news_data[i].news_comment_data[j].news_comment_writer_profile;
                                        tmp_news_comments.news_comment_contents       = resultData.news_data[i].news_comment_data[j].news_comment_contents;
                                        tmp_news_comments.news_comment_likes          = resultData.news_data[i].news_comment_data[j].news_comment_likes;
                                        tmp_news_comments.c_date = resultData.news_data[i].news_comment_data[j].c_date;

                                        try
                                        {
                                            tmpnews.news_comment_data.Add(tmp_news_comments);
                                        } catch (Exception e)
                                        {
                                        }
                                    }
                                }

                                Global.news.Add(tmpnews);
                                newsInfo.Add(tmpnews);
                            }

                            listview.ItemsSource = newsInfo;
                        }
                    }
                    else
                    {
                        await DisplayAlert("", resultMsg.resp, "はい");
                    }
                }
                catch
                {
                    await DisplayAlert("", Constants.NETWORK_ERROR, "はい");
                }
            }
        }
Exemple #5
0
        public NewsDetailPage(string selected_news_id, string title, string favorite_image_source)
        {
            InitializeComponent();
            label_title.Text    = title;
            img_favorite.Source = favorite_image_source;
            news_id             = selected_news_id;

            comments = new List <News_Comments>();

            int news_count = Global.news.Count;

            if (news_count != 0)
            {
                for (int i = 0; i < news_count; i++)
                {
                    if (string.Equals(selected_news_id, Global.news[i].news_id))
                    {
                        index = i;
                        break;
                    }
                }

                news_url               = Global.news[index].news_url;
                img_thumbnail.Source   = Global.news[index].news_image_url;
                lbl_news_title.Text    = Global.news[index].news_title;
                lbl_news_time.Text     = Global.news[index].news_date.ToString();
                lbl_news_source.Text   = Global.news[index].news_source;
                lbl_news_category.Text = Global.news[index].news_category;
                lbl_news_contents.Text = Global.news[index].news_contents;

                int comments_count = Global.news[index].news_comment_data.Count;
                if (comments_count != 0)
                {
                    for (int i = 0; i < comments_count; i++)
                    {
                        News_Comments tempComments = new News_Comments();

                        tempComments.news_comment_id             = Global.news[index].news_comment_data[i].news_comment_id;
                        tempComments.news_comment_writer_name    = Global.news[index].news_comment_data[i].news_comment_writer_name;
                        tempComments.news_comment_writer_image   = Global.news[index].news_comment_data[i].news_comment_writer_image;
                        tempComments.news_comment_writer_profile = Global.news[index].news_comment_data[i].news_comment_writer_profile;
                        tempComments.news_comment_contents       = Global.news[index].news_comment_data[i].news_comment_contents;
                        tempComments.news_comment_likes          = Global.news[index].news_comment_data[i].news_comment_likes;
                        tempComments.c_date = Global.news[index].news_comment_data[i].c_date;

                        if (string.IsNullOrEmpty(tempComments.news_comment_writer_image))
                        {
                            tempComments.news_comment_writer_image = "imgUser.png";
                        }
                        else
                        {
                            if (tempComments.news_comment_writer_image.Substring(0, 1) == "o")
                            {
                                tempComments.news_comment_writer_image = Constants.IMAGE_UPLOAD_URL_PREFIX + tempComments.news_comment_writer_image;
                            }
                            else if (tempComments.news_comment_writer_image.Substring(0, 1) == "t")
                            {
                                tempComments.news_comment_writer_image = Constants.IMAGE_UPLOAD_URL_PREFIX_TENANT + tempComments.news_comment_writer_image;
                            }
                        }

                        comments.Add(tempComments);
                    }

                    listview.ItemsSource = comments;
                }
            }

            listview.ItemSelected += DeselectItem;
        }