public List <SimpleNewsDTO> GetAllNewsSimple() { List <SimpleNewsDTO> news = new List <SimpleNewsDTO>(); ISession session = null; try { session = DataLayer.GetSession(); IEnumerable <News> retData = from n in session.QueryOver <News>().List() select n; foreach (News n in retData) { SimpleNewsDTO dto = new SimpleNewsDTO(n); //var newestDate = n.Modifications.Max(x => x.ModificationDate); //int LastModifiedUser = n.Modifications.First(x => x.ModificationDate == newestDate).User.Id; //dto.LastModifiedUser = new UserDTO(session.Load<User>(LastModifiedUser)); news.Add(dto); } session.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); if (session != null) { session.Close(); } } return(news); }
public SimpleNewsDTO GetSimpleNewsById(int newsId) { ISession session = null; SimpleNewsDTO result = null; try { session = DataLayer.GetSession(); News news = session.Load <News>(newsId); result = new SimpleNewsDTO(news); var newestDate = news.Modifications.Max(x => x.ModificationDate); int LastModifiedUser = news.Modifications.First(x => x.ModificationDate == newestDate).Id; result.LastModifiedUser = new UserDTO(session.Load <User>(LastModifiedUser)); session.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); if (session != null) { session.Close(); } } return(result); }
public SimpleNewsDTO CreateNews(SimpleNewsDTO dto, int userId) { SimpleNewsDTO result = newsData.CreateNews(dto, userId); //if (dto.BackgroundPicture != null) //{ // //loader.SaveMedia(news.BackgroundPicture.Id, news.Id, news.BackgroundPicture.GetPictureBytes()); // result.BackgroundPicture.PictureData = dto.BackgroundPicture.PictureData; //} return(result); }
public SimpleNewsDTO UpdateNews(SimpleNewsDTO simpleDTO, int userId) { SimpleNewsDTO result = null; ISession session = null; try { session = DataLayer.GetSession(); User user = session.Load <User>(userId); News news = session.Load <News>(simpleDTO.Id); news.Title = simpleDTO.Title; news.Content = simpleDTO.Content; if (simpleDTO.BackgroundPicture != null && news.BackgroundPicture == null) { news.BackgroundPicture = ExpandBackgroundPicture(simpleDTO.BackgroundPicture); } else if (simpleDTO.BackgroundPicture == null) { news.BackgroundPicture = null; } news.LastModified = DateTime.Now; NewsModified modification = new NewsModified(); modification.ModificationDate = DateTime.Now; modification.News = news; modification.User = user; session.SaveOrUpdate(news); session.Save(modification); session.Flush(); result = new SimpleNewsDTO(news); session.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); if (session != null) { session.Close(); } } return(result); }
public SimpleNewsDTO UpdateNews(SimpleNewsDTO simpleDTO, int userId) { SimpleNewsDTO dataResult = newsData.UpdateNews(simpleDTO, userId); if (dataResult != null && simpleDTO.BackgroundPicture != null) { //loader.SaveMedia(simpleDTO.BackgroundPicture.Id, simpleDTO.Id, simpleDTO.BackgroundPicture.GetPictureBytes()); dataResult.BackgroundPicture.PictureData = simpleDTO.BackgroundPicture.PictureData; } if (dataResult != null) { MessageQueueManager manager = MessageQueueManager.Instance; manager.PublishMessage(dataResult.Id, dataResult.Id, dataResult, MessageOperation.Update); } return(dataResult); }
public SimpleNewsDTO CreateNews(SimpleNewsDTO dto, int userId) { NewsDTO news = new NewsDTO(dto); SimpleNewsDTO result = null; ISession session = null; try { session = DataLayer.GetSession(); News newNews = ExpandDTO(news); newNews.LastModified = DateTime.Now; User user = session.Load <User>(userId); NewsModified modified = new NewsModified(); modified.News = newNews; modified.User = user; modified.ModificationDate = DateTime.Now; modified.News = newNews; ITransaction transaction = session.BeginTransaction(); session.SaveOrUpdate(newNews); session.Save(modified); session.Flush(); transaction.Commit(); result = new SimpleNewsDTO(newNews); session.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); if (session != null) { session.Close(); } } return(result); }
public SimpleNewsDTO UpdateNews([FromBody] SimpleNewsDTO simpleDTO, int userId) { service = Service.NewsService; return(service.UpdateNews(simpleDTO, userId)); }
public SimpleNewsDTO CreateNews([FromBody] SimpleNewsDTO news, int userId) { return(Service.NewsService.CreateNews(news, userId)); }