Beispiel #1
0
        public static bool DeleteNewsModifiaction(int modificationId)
        {
            ISession session = null;
            bool     result  = false;

            try
            {
                session = DataLayer.GetSession();
                NewsModified modification = session.Load <NewsModified>(modificationId);
                session.Delete(modification);
                session.Flush();
                session.Close();
                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (session != null)
                {
                    session.Close();
                }
            }

            return(result);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public static bool CreateNews(string title, string content,
                                      int userId)
        {
            bool     result  = false;
            ISession session = null;

            try
            {
                session = DataLayer.GetSession();
                News         news         = new News();
                User         user         = session.Load <User>(userId);
                NewsModified modifiaction = new NewsModified();
                modifiaction.ModificationDate = DateTime.Now;
                modifiaction.User             = user;
                modifiaction.News             = news;

                news.LastModified = DateTime.Now;
                news.Title        = title;
                news.Content      = content;
                //news.Pictures = new List<Picture>();
                //news.AudioRecordings = new List<Audio>();
                news.Modifications = new List <NewsModified>();
                news.Modifications.Add(modifiaction);

                ITransaction transaction = session.BeginTransaction();
                session.Save(news);
                session.Save(modifiaction);

                session.Flush();
                transaction.Commit();
                session.Close();
                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (session != null)
                {
                    session.Close();
                }
            }
            return(result);
        }
Beispiel #4
0
        //postoji li nacin da se naprave vrste modifikacija i da se u runtime odredjuje tip, pa da se i to nekako loguje
        //slicno kao command pattern
        public static bool UpdateNews(int userId, int newsId,
                                      string title, string content)
        {
            bool     result  = false;
            ISession session = null;

            try
            {
                session = DataLayer.GetSession();
                User user = session.Load <User>(userId);
                News news = session.Load <News>(newsId);
                news.Title        = title;
                news.Content      = content;
                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();
                session.Close();


                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (session != null)
                {
                    session.Close();
                }
            }
            return(result);
        }
Beispiel #5
0
        public NewsDTO CreateNews(NewsDTO news, int userId)
        {
            NewsDTO  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;
                newNews.Modifications.Add(modified);

                ITransaction transaction = session.BeginTransaction();

                session.SaveOrUpdate(newNews);
                // session.Save(modified);
                session.Flush();
                transaction.Commit();

                result = new NewsDTO(newNews);

                session.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (session != null)
                {
                    session.Close();
                }
            }
            return(result);
        }