Example #1
0
 public News Create(News news)
 {
     if (news == null)
         throw new ArgumentException(ERROR_CREATE_NEWS);
     _database.News.Add(news);
     return news;
 }
Example #2
0
 public void Edit(News news)
 {
     News newsInDb = _database.News.Find(news.NewsId);
     if (newsInDb == null)
     {
         Create(news);
     }
     else
     {
         _database.Entry(newsInDb).CurrentValues.SetValues(news);
         _database.Entry(newsInDb).State = System.Data.Entity.EntityState.Modified;
     }
 }
Example #3
0
 public Comment Create(User user, News publication, String content)
 {
     if (String.IsNullOrEmpty(content) || user == null)
         throw new ArgumentException(ERROR_CREATE_COMMENT);
     Comment comment = new Comment()
     {
         Owner = user,
         Content = content,
         Publication = publication,
         DatePublication = DateTime.Now,
         CommentId = Guid.NewGuid()
     };
     _database.Comments.Add(comment);
     return comment;
 }
Example #4
0
 public News Create(User user, String title, String content, String category, byte[] image = null)
 {
     if (String.IsNullOrEmpty(title) || String.IsNullOrEmpty(content) || user == null)
         throw new ArgumentException(ERROR_CREATE_NEWS);
     News news = new News()
     {
         Title = title,
         Content = content,
         Owner = user,
         Category = category,
         Image = image,
         DatePublication = DateTime.Now,
         NewsId = Guid.NewGuid()
     };
     _database.News.Add(news);
     return news;
 }
Example #5
0
        public ActionResult AddNews(News news, HttpPostedFileBase upload)
        {
            byte[] file = null;
            if (ModelState.IsValid)
            {
                if (upload != null)
                {
                    file = ConverterFileToBytes.Convert(upload);
                }
                using (UnitOfWork unit = new UnitOfWork())
                {
                    UserRepository userRep = new UserRepository(unit.DataContext);
                    User user = userRep.GetUserById(new Guid(Session["LoginUserID"].ToString()));
                    if (user != null)
                    {
                        NewsService newServ = new NewsService(unit.DataContext);
                        newServ.Create(user, news.Title, news.Content, news.Category, file);
                        unit.Commit();
                    }
                }
            }

            return RedirectToAction("Index");
        }
Example #6
0
 public ActionResult Edit(News news, HttpPostedFileBase upload)
 {
     if (ModelState.IsValid && Session["LoginUserID"] != null)
     {
         byte[] file = null;
         if (upload != null)
             file = ConverterFileToBytes.Convert(upload);
         using (UnitOfWork unit = new UnitOfWork())
         {
             NewsService newsServ = new NewsService(unit.DataContext);
             NewsRepository newsRep = new NewsRepository(unit.DataContext);
             UserRepository userRep = new UserRepository(unit.DataContext);
             CommentRepository comRep = new CommentRepository(unit.DataContext);
             news.NewsId = new Guid(Session["NewsId"].ToString());
             news.Image = file;
             news.DatePublication = newsRep.GetNewsById(news.NewsId).DatePublication;
             news.Owner = userRep.GetUserById(new Guid(Session["LoginUserID"].ToString()));
             news.Comments = comRep.GetCommentsByPublicationId(new Guid(Session["LoginUserID"].ToString())).ToList();
             newsServ.Edit(news);
             unit.Commit();
         }
         return RedirectToAction("Index");
     }
     return HttpNotFound();
 }
Example #7
0
 public void Delete(News news)
 {
     if (news == null)
         throw new ArgumentException(ERROR_DELETE_NEWS);
     _database.News.Remove(news);
 }