/// <summary>
 /// Adds a new Article to the database and returns the success of the operation.
 /// The id field of the parameter will be ignored when adding to the database.
 /// </summary>
 public static bool AddArticle(Dbo.Article article)
 {
     try
     {
         using (ProjectDBEntities ctx = new ProjectDBEntities())
         {
             ctx.T_Article.Add(new T_Article()
             {
                 Title     = article.Title,
                 IdAuthor  = article.IdAuthor,
                 Date      = article.Date,
                 Image     = article.Image,
                 Text      = article.Text,
                 Viewcount = 0
             });
             if (ctx.SaveChanges() == 0)
             {
                 return(false);
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 /// <summary>
 /// Increments the viewcounter of the matching article and returns the success of the operation.
 /// </summary>
 public static bool IncrementArticleViewcountById(long id)
 {
     try
     {
         using (ProjectDBEntities ctx = new ProjectDBEntities())
         {
             var article = (from tmp in ctx.T_Article
                            where tmp.Id == id
                            select tmp).First();
             article.Viewcount = article.Viewcount + 1;
             if (ctx.SaveChanges() == 0)
             {
                 return(false);
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #3
0
 /// <summary>
 /// Adds a new User to the database and returns the success of the operation.
 /// The id field of the parameter will be ignored when adding to the database.
 /// </summary>
 public static bool AddUser(Dbo.User user)
 {
     try
     {
         using (ProjectDBEntities ctx = new ProjectDBEntities())
         {
             ctx.T_User.Add(new T_User()
             {
                 Name     = user.Name,
                 Password = user.Password,
                 Admin    = user.Admin
             });
             if (ctx.SaveChanges() == 0)
             {
                 return(false);
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }