public ResultViewData Delete(string id, string subjectId)
 {
     try
     {
         var model = new SubjectNews
         {
             Id = string.IsNullOrEmpty(id) ? 0 : int.Parse(id),
             SubjectId = int.Parse(subjectId),
         };
         SubjectManagementService.DeleteNews(model);
         return new ResultViewData()
         {
             Message = "Новость успешно удалена",
             Code = "200"
         };
     }
     catch (Exception)
     {
         return new ResultViewData()
         {
             Message = "Произошла ошибка при удалении новости",
             Code = "500"
         };
     }
 }
Esempio n. 2
0
 public NewsDataViewModel(SubjectNews news)
 {
     Body = news.Body;
     NewsId = news.Id;
     Title = news.Title;
     SubjectId = news.SubjectId;
     DateCreate = news.EditDate.ToShortDateString();
 }
Esempio n. 3
0
 public NewsViewData(SubjectNews news)
 {
     Body = news.Body;
     NewsId = news.Id;
     Title = news.Title;
     SubjectId = news.SubjectId;
     DateCreate = news.EditDate.ToShortDateString();
     Disabled = news.Disabled;
 }
Esempio n. 4
0
        public SubjectNews SaveNews(SubjectNews news)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                repositoriesContainer.SubjectRepository.SaveNews(news);

                repositoriesContainer.ApplyChanges();
            }

            return news;
        }
Esempio n. 5
0
 public void DeleteNews(SubjectNews news)
 {
     using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
     {
         repositoriesContainer.SubjectRepository.DeleteNews(news);
     }
 }
        public ResultViewData Save(string subjectId, string id, string title, string body, bool disabled, bool isOldDate)
        {
            try
            {
                var newsIds = string.IsNullOrEmpty(id) ? 0 : int.Parse(id);
                var date = DateTime.Now;

                if ((newsIds != 0 && isOldDate) || (newsIds != 0 && disabled))
                {
                    date = SubjectManagementService.GetNews(newsIds, int.Parse(subjectId)).EditDate;
                }
                else if ((newsIds != 0 && !disabled))
                {
                    if (SubjectManagementService.GetNews(newsIds, int.Parse(subjectId)).Disabled)
                    {
                        date = DateTime.Now;
                    }
                }

                var model = new SubjectNews
                                {
                                    Id = newsIds,
                                    SubjectId = int.Parse(subjectId),
                                    Body = body,
                                    EditDate = date,
                                    Title = title,
                                    Disabled = disabled
                                };
                SubjectManagementService.SaveNews(model);
                return new ResultViewData()
                {
                    Message = "Новость успешно сохранена",
                    Code = "200"
                };
            }
            catch (Exception)
            {
                return new ResultViewData()
                {
                    Message = "Произошла ошибка при сохранении новости",
                    Code = "500"
                };
            }
        }