public void DeleteNews(DiplomProjectNews news)
 {
     var cpnews = Context.DiplomProjectNewses.Single(x => x.Id == news.Id && x.LecturerId == news.LecturerId);
     Context.DiplomProjectNewses.Remove(cpnews);
     Context.SaveChanges();
 }
        public DiplomProjectNews SaveNews(DiplomProjectNews news, IList<Attachment> attachments, Int32 userId)
        {
            using (var repositoriesContainer = new LmPlatformRepositoriesContainer())
            {
                if (!string.IsNullOrEmpty(news.Attachments))
                {
                    var deleteFiles =
                        repositoriesContainer.AttachmentRepository.GetAll(
                            new Query<Attachment>(e => e.PathName == news.Attachments)).ToList().Where(e => attachments.All(x => x.Id != e.Id)).ToList();

                    foreach (var attachment in deleteFiles)
                    {
                        FilesManagementService.DeleteFileAttachment(attachment);
                    }
                }
                else
                {
                    news.Attachments = GetGuidFileName();
                }

                FilesManagementService.SaveFiles(attachments.Where(e => e.Id == 0), news.Attachments);

                foreach (var attachment in attachments)
                {
                    if (attachment.Id == 0)
                    {
                        attachment.PathName = news.Attachments;
                        repositoriesContainer.AttachmentRepository.Save(attachment);
                    }
                }
            }

            var cpEditNews = Context.DiplomProjectNewses.FirstOrDefault(x => x.Id == news.Id && x.LecturerId == news.LecturerId);
            if (cpEditNews != null)
            {
                CourseProjectNews cpnews = new CourseProjectNews();
                cpEditNews.Body = news.Body;
                cpEditNews.Disabled = news.Disabled;
                cpEditNews.EditDate = news.EditDate;
                cpEditNews.LecturerId = news.LecturerId;
                cpEditNews.Attachments = news.Attachments;
                cpEditNews.Title = news.Title;
            }
            else {
                Context.DiplomProjectNewses.Add(news);
            }
            Context.SaveChanges();

            return news;
        }