Ejemplo n.º 1
0
        /// <summary>
        /// Изменяет уже имеющуюся новость
        /// </summary>
        /// <param name="news"></param>
        public void Update(NewsDetailDto news)
        {
            News _news = _mapper.Map <News>(news);

            _db.NewsRep.Update(_news);
            _db.Save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Добавляет запись в бд
        /// </summary>
        /// <param name="news">Новость</param>
        public void Add(NewsDetailDto news)
        {
            News _news = _mapper.Map <News>(news);

            _news.Id = new Guid();
            _news.CreationDateTime = DateTime.Now;
            _news.ChangingDateTime = DateTime.Now;
            _db.NewsRep.Add(_news);
            _db.Save();
        }
Ejemplo n.º 3
0
        // POST api/news
        public void Post(NewsDetailDto data)
        {
            using (var context = new BasicAppEntityContext())
            {
                context.News.Add(new News
                {
                    Title        = data.Title,
                    Content      = data.Content,
                    CreationDate = data.CreationDate,
                    Image        = data.Image
                });

                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        // PUT api/news/5
        public void Put(NewsDetailDto data)
        {
            using (var context = new BasicAppEntityContext())
            {
                var item = context.News.SingleOrDefault(x => x.Id == data.Id);

                item.Title        = data.Title;
                item.Content      = data.Content;
                item.Image        = data.Image;
                item.CreationDate = data.CreationDate;

                context.Entry(item).State = System.Data.Entity.EntityState.Modified;

                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public NewsDetailDto GetNewsDetail(int id)
        {
            var news    = _context.News.Where(w => w.Id == id && !w.IsDeleted).FirstOrDefault() ?? new News();
            var similar = _context.News.Where(w => w.Id != id && !w.IsDeleted).OrderByDescending(p => p.Id).Take(4).Select(s => new NewsDto
            {
                Id    = s.Id,
                Image = s.Image,
                Title = _currentLang == (int)Language.Farsi ? s.Title : s.EnglishTitle,
            }).ToList();

            var newsItem = new NewsDetailDto
            {
                Id               = news.Id,
                Image            = news.Image,
                Title            = _currentLang == (int)Language.Farsi ? news.Title : news.EnglishTitle,
                ShortDescription = _currentLang == (int)Language.Farsi ? news.ShortDescription : news.EnglishShortDescription,
                Description      = _currentLang == (int)Language.Farsi ? news.Description : news.EnglishDescription,
                SimilarNews      = similar
            };

            return(newsItem);
        }
Ejemplo n.º 6
0
 public void UpdateNews(NewsDetailDto news)
 {
     _newsService.Update(news);
 }
Ejemplo n.º 7
0
 public void AddNews(NewsDetailDto news)
 {
     _newsService.Add(news);
 }