コード例 #1
0
        public static List <DBO.Language> GetListLanguage()
        {
            List <DBO.Language> result = new List <DBO.Language>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Language> list = bdd.T_Language.ToList();
                    foreach (T_Language language in list)
                    {
                        DBO.Language newLang = new DBO.Language()
                        {
                            Name      = language.name,
                            Id        = language.id,
                            ShortName = language.shortname
                        };
                        result.Add(newLang);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #2
0
ファイル: Article.cs プロジェクト: J0bba/DotNetProject
 public static DBO.Article GetArticle(long id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article article = bdd.T_Article.Where(x => x.id == id).FirstOrDefault();
             if (article != null)
             {
                 DBO.Article result = new DBO.Article()
                 {
                     Id          = article.id,
                     Title       = article.title,
                     Content     = article.content,
                     CreatedDate = article.created_date,
                     IdCreator   = article.id_creator,
                     Validated   = article.validated
                 };
                 return(result);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
コード例 #3
0
ファイル: User.cs プロジェクト: J0bba/DotNetProject
        public static bool CreateUser(DBO.User user)
        {
            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    T_User newUser = new T_User()
                    {
                        email     = user.Email,
                        firstname = user.Firstname,
                        lastname  = user.Lastname,
                        password  = user.Password,
                        role      = (int)user.Role
                    };

                    bdd.T_User.Add(newUser);
                    bdd.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #4
0
ファイル: Translation.cs プロジェクト: J0bba/DotNetProject
 public static DBO.Translation GetTranslationById(long id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Translation translation = bdd.T_Translation.Where(x => x.id == id).FirstOrDefault();
             if (translation != null)
             {
                 DBO.Translation newTranslation = new DBO.Translation()
                 {
                     Content      = translation.content,
                     Id           = translation.id,
                     IdArticle    = translation.id_article,
                     IdLanguage   = translation.id_language,
                     IdTranslator = translation.id_translator,
                     Validated    = translation.validated
                 };
                 return(newTranslation);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
コード例 #5
0
ファイル: Translation.cs プロジェクト: J0bba/DotNetProject
        public static bool CreateTranslation(DBO.Translation translation)
        {
            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    T_Translation newTranslation = new T_Translation()
                    {
                        content       = translation.Content,
                        id_article    = translation.IdArticle,
                        id_language   = translation.IdLanguage,
                        id_translator = translation.IdTranslator,
                        validated     = translation.Validated
                    };

                    bdd.T_Translation.Add(newTranslation);
                    bdd.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #6
0
ファイル: Translation.cs プロジェクト: J0bba/DotNetProject
        public static bool UpdateTranslation(DBO.Translation translation)
        {
            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    T_Translation oldTranslation = bdd.T_Translation.Where(x => x.id == translation.Id).FirstOrDefault();
                    if (oldTranslation != null)
                    {
                        oldTranslation.content       = translation.Content;
                        oldTranslation.id_article    = translation.IdArticle;
                        oldTranslation.id_language   = translation.IdLanguage;
                        oldTranslation.id_translator = translation.IdTranslator;
                        oldTranslation.validated     = translation.Validated;

                        bdd.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #7
0
ファイル: Translation.cs プロジェクト: J0bba/DotNetProject
        public static List <DBO.Translation> GetListNonValidatedTranslation()
        {
            List <DBO.Translation> result = new List <DBO.Translation>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Translation> translations = bdd.T_Translation.Where(x => x.validated == false).ToList();
                    foreach (T_Translation translation in translations)
                    {
                        DBO.Translation newTranslation = new DBO.Translation()
                        {
                            Content      = translation.content,
                            Id           = translation.id,
                            IdArticle    = translation.id_article,
                            IdLanguage   = translation.id_language,
                            IdTranslator = translation.id_translator,
                            Validated    = translation.validated
                        };
                        result.Add(newTranslation);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #8
0
ファイル: Comment.cs プロジェクト: J0bba/DotNetProject
        public static List <DBO.Comment> GetListCommentByArticle(long article_id)
        {
            List <DBO.Comment> result = new List <DBO.Comment>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Comment> list = bdd.T_Comment.Where(x => x.id_article == article_id).ToList();
                    foreach (T_Comment comment in list)
                    {
                        DBO.Comment newComment = new DBO.Comment()
                        {
                            Id        = comment.id,
                            Content   = comment.content,
                            IdArticle = comment.id_article,
                            Date      = comment.date,
                            IdUser    = comment.id_user
                        };
                        result.Add(newComment);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #9
0
ファイル: UserLike.cs プロジェクト: J0bba/DotNetProject
        public static List <DBO.UserLike> GetListUserLikeByArticle(long article_id)
        {
            List <DBO.UserLike> result = new List <DBO.UserLike>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_User_Like> list = bdd.T_User_Like.Where(x => x.id_article == article_id).ToList();
                    foreach (T_User_Like userLike in list)
                    {
                        DBO.UserLike newLike = new DBO.UserLike()
                        {
                            Id        = userLike.id,
                            IdArticle = userLike.id_article,
                            IdUser    = userLike.id_user
                        };
                        result.Add(newLike);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #10
0
ファイル: Article.cs プロジェクト: J0bba/DotNetProject
 public static bool CreateArticle(ref DBO.Article article)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article newArticle = new T_Article()
             {
                 title        = article.Title,
                 content      = article.Content,
                 id_creator   = article.IdCreator,
                 created_date = article.CreatedDate,
                 validated    = article.Validated
             };
             bdd.T_Article.Add(newArticle);
             bdd.SaveChanges();
             article.Id = newArticle.id;
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.ToString());
         return(false);
     }
 }
コード例 #11
0
ファイル: ArticleAttach.cs プロジェクト: J0bba/DotNetProject
        public static List <DBO.ArticleAttach> GetListArticleAttachByArticle(long article_id)
        {
            List <DBO.ArticleAttach> result = new List <DBO.ArticleAttach>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Article_Attach> list = bdd.T_Article_Attach.Where(x => x.id_article == article_id).ToList();
                    foreach (T_Article_Attach ArticleAttach in list)
                    {
                        DBO.ArticleAttach newAttach = new DBO.ArticleAttach()
                        {
                            Id        = ArticleAttach.id,
                            IdArticle = ArticleAttach.id_article,
                            FilePath  = ArticleAttach.file_path,
                            Name      = ArticleAttach.name
                        };
                        result.Add(newAttach);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #12
0
 public static DBO.ArticleImage GetArticleImageByArticle(long article_id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article_Image ArticleImage = bdd.T_Article_Image.Where(x => x.id_article == article_id).First();
             if (ArticleImage != null)
             {
                 DBO.ArticleImage newAttach = new DBO.ArticleImage()
                 {
                     Id        = ArticleImage.id,
                     IdArticle = ArticleImage.id_article,
                     ImagePath = ArticleImage.image_path,
                     Name      = ArticleImage.name
                 };
                 return(newAttach);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
コード例 #13
0
ファイル: Article.cs プロジェクト: J0bba/DotNetProject
        public static List <DBO.Article> GetListArticleByText(string word)
        {
            List <DBO.Article> result = new List <DBO.Article>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Article> list = bdd.T_Article.Where(x => x.content.Contains(word) || x.title.Contains(word)).ToList();
                    foreach (T_Article article in list)
                    {
                        DBO.Article newArticle = new DBO.Article()
                        {
                            Id          = article.id,
                            Title       = article.title,
                            Content     = article.content,
                            CreatedDate = article.created_date,
                            Validated   = article.validated,
                            IdCreator   = article.id_creator
                        };
                        result.Add(newArticle);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #14
0
        public static List <DBO.ArticleImage> GetListWithWord(string word)
        {
            List <DBO.ArticleImage> result = new List <DBO.ArticleImage>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Article_Image> list = bdd.T_Article_Image.Where(x => x.name.ToLower().Contains(word)).ToList();
                    foreach (T_Article_Image ArticleImage in list)
                    {
                        DBO.ArticleImage newAttach = new DBO.ArticleImage()
                        {
                            Id        = ArticleImage.id,
                            IdArticle = ArticleImage.id_article,
                            ImagePath = ArticleImage.image_path,
                            Name      = ArticleImage.name
                        };
                        result.Add(newAttach);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #15
0
ファイル: User.cs プロジェクト: J0bba/DotNetProject
 public static DBO.User GetUserById(long id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_User user = bdd.T_User.Where(x => x.id == id).FirstOrDefault();
             if (user != null)
             {
                 DBO.User result = new DBO.User()
                 {
                     Email     = user.email,
                     Firstname = user.firstname,
                     Id        = user.id,
                     Lastname  = user.lastname,
                     Password  = user.password,
                     Role      = (BusinessManagement.UserRoles.Roles)user.role
                 };
                 return(result);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
コード例 #16
0
ファイル: Message.cs プロジェクト: J0bba/DotNetProject
        public static List <DBO.Message> GetListMessageByUser(long user_id)
        {
            List <DBO.Message> result = new List <DBO.Message>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_Message> list = bdd.T_Message.Where(x => x.id_sender == user_id || x.id_receiver == user_id).ToList();
                    foreach (T_Message message in list)
                    {
                        DBO.Message newMessage = new DBO.Message()
                        {
                            Content    = message.content,
                            Date       = message.date,
                            Id         = message.id,
                            IdReceiver = message.id_receiver,
                            IdSender   = message.id_sender,
                            IsSeen     = message.isSeen.Value
                        };
                        result.Add(newMessage);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #17
0
ファイル: Article.cs プロジェクト: J0bba/DotNetProject
        public static bool UpdateArticle(DBO.Article article)
        {
            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    T_Article oldarticle = bdd.T_Article.Where(x => x.id == article.Id).FirstOrDefault();
                    if (oldarticle != null)
                    {
                        oldarticle.title        = article.Title;
                        oldarticle.content      = article.Content;
                        oldarticle.id_creator   = article.IdCreator;
                        oldarticle.validated    = article.Validated;
                        oldarticle.created_date = article.CreatedDate;

                        bdd.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #18
0
ファイル: User.cs プロジェクト: J0bba/DotNetProject
        public static List <DBO.User> GetUsersUnderRole(long id, BusinessManagement.UserRoles.Roles role)
        {
            List <DBO.User> result = new List <DBO.User>();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    List <T_User> list = bdd.T_User.Where(x => x.id != id && x.role <= (int)role).ToList();
                    foreach (T_User user in list)
                    {
                        DBO.User newUser = new DBO.User()
                        {
                            Email     = user.email,
                            Firstname = user.firstname,
                            Id        = user.id,
                            Lastname  = user.lastname,
                            Password  = user.password,
                            Role      = (BusinessManagement.UserRoles.Roles)user.role
                        };
                        result.Add(newUser);
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #19
0
ファイル: Message.cs プロジェクト: J0bba/DotNetProject
        public static bool CreateMessage(DBO.Message message)
        {
            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    T_Message newMessage = new T_Message()
                    {
                        content     = message.Content,
                        date        = message.Date,
                        id_receiver = message.IdReceiver,
                        id_sender   = message.IdSender,
                        isSeen      = message.IsSeen
                    };

                    bdd.T_Message.Add(newMessage);
                    bdd.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #20
0
ファイル: Message.cs プロジェクト: J0bba/DotNetProject
 public static bool DoesUserHaveNewMessage(int user_id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Message message = bdd.T_Message.Where(x => x.id_receiver == user_id && x.isSeen == false).FirstOrDefault();
             return(message != null);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
コード例 #21
0
ファイル: User.cs プロジェクト: J0bba/DotNetProject
 public static bool DeleteUser(long id)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             bdd.T_User.Remove(bdd.T_User.Where(x => x.id == id).FirstOrDefault());
             bdd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
コード例 #22
0
ファイル: Article.cs プロジェクト: J0bba/DotNetProject
        public static List <Tuple <DBO.Article, List <DBO.Language> > > GetListArticleWithMissingTrans()
        {
            List <Tuple <DBO.Article, List <DBO.Language> > > result = new List <Tuple <DBO.Article, List <DBO.Language> > >();

            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    var list = bdd.T_Article.GroupJoin(bdd.T_Translation, article => article.id, translation => translation.id_article, (article, translation) => new { article, translation }).ToList();
                    foreach (var elm in list)
                    {
                        List <DBO.Language> languages = Language.GetListLanguage();
                        if (elm.translation.Count() != languages.Count)
                        {
                            DBO.Article newArticle = new DBO.Article()
                            {
                                Id          = elm.article.id,
                                Title       = elm.article.title,
                                Content     = elm.article.content,
                                CreatedDate = elm.article.created_date,
                                Validated   = elm.article.validated,
                                IdCreator   = elm.article.id_creator
                            };
                            foreach (var obj in elm.translation)
                            {
                                foreach (var language in languages)
                                {
                                    if (obj.id_language == language.Id)
                                    {
                                        languages.Remove(language);
                                    }
                                }
                            }
                            Tuple <DBO.Article, List <DBO.Language> > item = new Tuple <DBO.Article, List <DBO.Language> >(newArticle, languages);
                            result.Add(item);
                        }
                    }
                    return(result);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(result);
            }
        }
コード例 #23
0
ファイル: User.cs プロジェクト: J0bba/DotNetProject
 public static bool ValidateUser(string email, string password)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_User user = bdd.T_User.Where(x => x.email == email && x.password == password).FirstOrDefault();
             if (user != null)
             {
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
コード例 #24
0
ファイル: User.cs プロジェクト: J0bba/DotNetProject
 public static string GetPasswordByUser(string email)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_User user = bdd.T_User.Where(x => x.email == email).FirstOrDefault();
             if (user != null)
             {
                 return(user.password);
             }
             return("");
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return("");
     }
 }
コード例 #25
0
ファイル: Comment.cs プロジェクト: J0bba/DotNetProject
 public static bool UpdateComment(DBO.Comment comment)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Comment oldComment = bdd.T_Comment.Where(x => x.id == comment.Id).FirstOrDefault();
             oldComment.content    = comment.Content;
             oldComment.id_article = comment.IdArticle;
             oldComment.id_user    = comment.IdUser;
             oldComment.date       = comment.Date;
             bdd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
コード例 #26
0
ファイル: Message.cs プロジェクト: J0bba/DotNetProject
 public static bool UpdateMessage(DBO.Message message)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Message oldMessage = bdd.T_Message.Where(x => x.id == message.Id).FirstOrDefault();
             oldMessage.content     = message.Content;
             oldMessage.date        = message.Date;
             oldMessage.id_receiver = message.IdReceiver;
             oldMessage.id_sender   = message.IdSender;
             oldMessage.isSeen      = message.IsSeen;
             bdd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
コード例 #27
0
 public static bool CreateLanguage(DBO.Language language)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Language newLanguage = new T_Language()
             {
                 name      = language.Name,
                 shortname = language.ShortName
             };
             bdd.T_Language.Add(newLanguage);
             bdd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
コード例 #28
0
 public static bool UpdateLanguage(DBO.Language language)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Language oldLanguage = bdd.T_Language.Where(x => x.id == language.Id).FirstOrDefault();
             if (oldLanguage != null)
             {
                 oldLanguage.name      = language.Name;
                 oldLanguage.shortname = language.ShortName;
                 bdd.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }
コード例 #29
0
ファイル: UserLike.cs プロジェクト: J0bba/DotNetProject
        public static bool CreateUserLike(DBO.UserLike userLike)
        {
            try
            {
                using (MeditateBookEntities bdd = new MeditateBookEntities())
                {
                    T_User_Like newUserLike = new T_User_Like()
                    {
                        id_article = userLike.IdArticle,
                        id_user    = userLike.IdUser
                    };

                    bdd.T_User_Like.Add(newUserLike);
                    bdd.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
コード例 #30
0
 public static bool CreateArticleImage(DBO.ArticleImage articleImage)
 {
     try
     {
         using (MeditateBookEntities bdd = new MeditateBookEntities())
         {
             T_Article_Image newArticleAttach = new T_Article_Image()
             {
                 id_article = articleImage.IdArticle,
                 image_path = articleImage.ImagePath,
                 name       = articleImage.Name
             };
             bdd.T_Article_Image.Add(newArticleAttach);
             bdd.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(false);
     }
 }