public System.Web.Mvc.JsonResult Delete([FromBody] CourseProjectNews deleteData)
 {
     try
     {
         CpManagementService.DeleteNews(deleteData);
         return(new System.Web.Mvc.JsonResult()
         {
             Data = new
             {
                 Message = "Объявление успешно удалено",
                 Error = false
             }
         });
     }
     catch (Exception)
     {
         return(new System.Web.Mvc.JsonResult()
         {
             Data = new
             {
                 Message = "Произошла ошибка при удалении новости",
                 Error = true
             }
         });
     }
 }
 public System.Web.Mvc.JsonResult Save([FromBody] CourseProjectNews model)
 {
     try
     {
         model.EditDate = DateTime.Now;
         CpManagementService.SaveNews(model);
         return(new System.Web.Mvc.JsonResult()
         {
             Data = new
             {
                 Message = "Новость успешно сохранена",
                 Error = false
             }
         });
     }
     catch (Exception)
     {
         return(new System.Web.Mvc.JsonResult()
         {
             Data = new
             {
                 Message = "Произошла ошибка при сохранении новости",
                 Error = true
             }
         });
     }
 }
        public void DeleteNews(CourseProjectNews news)
        {
            var cpnews = Context.CourseProjectNews.Single(x => x.Id == news.Id && x.SubjectId == news.SubjectId);

            Context.CourseProjectNews.Remove(cpnews);
            Context.SaveChanges();
        }
        public CourseProjectNews SaveNews(CourseProjectNews news, IList <Attachment> attachments, int 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.CourseProjectNews.FirstOrDefault(x => x.Id == news.Id && x.SubjectId == news.SubjectId);

            if (cpEditNews != null)
            {
                cpEditNews.Body        = news.Body;
                cpEditNews.Disabled    = news.Disabled;
                cpEditNews.EditDate    = news.EditDate;
                cpEditNews.SubjectId   = news.SubjectId;
                cpEditNews.Attachments = news.Attachments;
                cpEditNews.Title       = news.Title;
            }
            else
            {
                Context.CourseProjectNews.Add(news);
            }

            Context.SaveChanges();

            return(news);
        }
Example #5
0
 public IActionResult Delete([FromBody] CourseProjectNews deleteData)
 {
     try
     {
         CpManagementService.DeleteNews(deleteData);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(ServerError500(ex.Message));
     }
 }
Example #6
0
        public CourseProjectNews SaveNews(CourseProjectNews news)
        {
            var cpEditNews = Context.CourseProjectNewses.FirstOrDefault(x => x.Id == news.Id && x.SubjectId == news.SubjectId);

            if (cpEditNews != null)
            {
                CourseProjectNews cpnews = new CourseProjectNews();
                cpEditNews.Body      = news.Body;
                cpEditNews.Disabled  = news.Disabled;
                cpEditNews.EditDate  = news.EditDate;
                cpEditNews.SubjectId = news.SubjectId;
                cpEditNews.Title     = news.Title;
            }
            else
            {
                Context.CourseProjectNewses.Add(news);
            }
            Context.SaveChanges();

            return(news);
        }