Example #1
0
        public Result <List <ArticleDTO> > GetIndexArticleList(int count, int userID)
        {
            var exp = DbUtilityFactory.GetDbUtility().GetSqlExpression <ArticleEntity>();

            exp.Where(a => a.userID == userID);
            exp.OrderByDescending(a => a.articleDate);
            var data = DbUtilityFactory.GetDbUtility().Paged <ArticleEntity>(a => a.articleDate, 1, 6);

            if (data.Any())
            {
                return(new Result <List <ArticleDTO> >()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = data.Select <ArticleEntity, ArticleDTO>(a => new ArticleDTO()
                    {
                        articleAbstract = a.articleAbstract,
                        articleDate = a.articleDate,
                        articleID = a.articleID,
                        articleTitle = a.articleTitle
                    }).ToList()
                });
            }
            else
            {
                return(new Result <List <ArticleDTO> >()
                {
                    IsSuccess = false,
                    ReturnMessage = "没有记录"
                });
            }
        }
Example #2
0
        public Result <int> AddNewArticle(ArticleDTO dto)
        {
            var result = DbUtilityFactory.GetDbUtility().Add(new ArticleEntity()
            {
                categoryID       = dto.categoryID,
                articleAbstract  = dto.articleAbstract,
                articleContain   = dto.articleContain,
                articleCopyright = dto.articleCopyright,
                articleDate      = DateTime.Now,
                articleTitle     = dto.articleTitle,
                userID           = dto.userID
            });

            if (result > 0)
            {
                return(new Result <int>()
                {
                    ReturnMessage = "添加成功",
                    IsSuccess = true,
                    ReturnValue = result
                });
            }
            else
            {
                return(new Result <int>()
                {
                    ReturnMessage = "添加失败",
                    IsSuccess = false,
                    ReturnValue = result
                });
            }
        }
Example #3
0
        public Result <string> GetCategoryNameByArticleID(int articleID)
        {
            var exp = DbUtilityFactory.GetDbUtility().GetSqlExpression <CategoryEntity>();

            exp.LeftJoin <ArticleEntity>((a, b) => a.categoryID == b.categoryID);
            exp.Where <ArticleEntity>(a => a.articleID == articleID);
            var data = DbUtilityFactory.GetDbUtility().GetList(exp);

            if (data == null)
            {
                return(new Result <string>()
                {
                    IsSuccess = false,
                    ReturnMessage = "出现错误"
                });
            }
            if (data.Any())
            {
                return(new Result <string>()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = data.First().categoryName
                });
            }
            else
            {
                return(new Result <string>()
                {
                    IsSuccess = false,
                    ReturnMessage = "没有找到栏目名称"
                });
            }
        }
Example #4
0
        public Result <ArticleDTO> GetArticleByArticleID(int articleID)
        {
            var data = DbUtilityFactory.GetDbUtility().GetSingle <ArticleEntity>(a => a.articleID == articleID);

            if (data != null)
            {
                return(new Result <ArticleDTO>()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = new ArticleDTO()
                    {
                        articleAbstract = data.articleAbstract,
                        articleContain = data.articleContain,
                        articleCopyright = data.articleCopyright,
                        articleDate = data.articleDate,
                        articleID = articleID,
                        articleTitle = data.articleTitle,
                        categoryID = data.categoryID,
                        categoryName = LocalServiceLocator.GetService <IMyBlogService>().GetCategoryNameByCategoryID(data.categoryID).ReturnValue,
                        userID = data.userID
                    }
                });
            }
            else
            {
                return(new Result <ArticleDTO>()
                {
                    IsSuccess = false,
                    ReturnMessage = "没有找到文章"
                });
            }
        }
 public Result<int> AddProject(ProjectDTO projectDTO)
 {
     var result = DbUtilityFactory.GetDbUtility().Add(new ProjectEntity()
     {
         projectName = projectDTO.projectName,
         userID = projectDTO.userID
     });
     if(result == 1)
     {
         return new Result<int>()
         {
             IsSuccess = true,
             ReturnValue = result,
             ReturnMessage = "添加成功"
         };
     }else
     {
         return new Result<int>()
         {
             IsSuccess = false,
             ReturnMessage = "添加失败"
         };
     }
     
 }
Example #6
0
        public Result <UserInfoDTO> CheckUser(string passport)
        {
            var userNameMd5 = passport.Substring(0, 32);
            var passwordMd5 = passport.Substring(32);
            var userInfo    = DbUtilityFactory.GetDbUtility().GetSingle <UserEntity>(a => a.userNameMd5 == userNameMd5);

            if (userInfo != null && userInfo.passwordMd5 == passwordMd5)
            {
                return(new Result <UserInfoDTO>()
                {
                    IsSuccess = true,
                    ReturnValue = new UserInfoDTO()
                    {
                        cookiePassport = userInfo.userNameMd5 + userInfo.passwordMd5,
                        userName = userInfo.userName,
                        userID = userInfo.userID,
                        userLevel = userInfo.userLevel,
                        nickName = userInfo.nickName
                    }
                });
            }
            else
            {
                return(new Result <UserInfoDTO>()
                {
                    IsSuccess = false,
                    ReturnMessage = "登录失效,请重新登录"
                });
            }
        }
Example #7
0
        public Result <UserInfoDTO> GetUserObj(int userID)
        {
            var userInfo = DbUtilityFactory.GetDbUtility().GetSingle <UserEntity>(a => a.userID == userID);

            if (userID != 0 && userInfo != null)
            {
                return(new Result <UserInfoDTO>()
                {
                    IsSuccess = true,
                    ReturnValue = new UserInfoDTO()
                    {
                        nickName = userInfo.nickName,
                        userID = userInfo.userID,
                        userLevel = userInfo.userLevel,
                        userName = userInfo.userName
                    }
                });
            }
            else
            {
                return(new Result <UserInfoDTO>()
                {
                    IsSuccess = false,
                    ReturnMessage = "没有找到此userID的记录"
                });
            }
        }
Example #8
0
        /// <summary>
        /// 添加栏目
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>成功返回"成功",失败返回"添加失败",成功与否都会返回受影响条数</returns>
        public Result <int> AddCategory(CategoryDTO dto)
        {
            var result = DbUtilityFactory.GetDbUtility().Add <CategoryEntity>(new CategoryEntity()
            {
                categoryName = dto.categoryName,
                projectID    = dto.projectID,
                userID       = dto.userID
            });

            if (result == 1)
            {
                return(new Result <int>()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = result
                });
            }
            else
            {
                return(new Result <int>()
                {
                    IsSuccess = false,
                    ReturnMessage = "添加失败",
                    ReturnValue = result
                });
            }
        }
Example #9
0
        public Result <int> EditArticle(ArticleDTO dto)
        {
            var result = DbUtilityFactory.GetDbUtility().Update(new ArticleEntity()
            {
                articleID        = dto.articleID,
                articleAbstract  = dto.articleAbstract,
                articleContain   = dto.articleContain,
                articleCopyright = dto.articleCopyright,
                articleDate      = DateTime.Now,
                articleTitle     = dto.articleTitle,
                categoryID       = dto.categoryID,
                userID           = dto.userID
            }, a => a.articleID == dto.articleID);

            if (result == 1)
            {
                return(new Result <int>()
                {
                    ReturnMessage = "修改成功",
                    IsSuccess = true,
                    ReturnValue = result
                });
            }
            else
            {
                return(new Result <int>()
                {
                    ReturnMessage = "修改失败",
                    IsSuccess = false,
                    ReturnValue = result
                });
            }
        }
Example #10
0
        public Result <List <MenuDTO> > GetMenu(int userID)
        {
            var pexp = DbUtilityFactory.GetDbUtility().GetSqlExpression <ProjectEntity>();

            pexp.Where(a => a.userID == userID);
            var projects = DbUtilityFactory.GetDbUtility().GetList(pexp);
            var menuList = new List <MenuDTO>();

            foreach (var i in projects)
            {
                var cexp      = DbUtilityFactory.GetDbUtility().GetSqlExpression <CategoryEntity>();
                var projectID = i.projectID;
                cexp.Where(a => a.projectID == projectID);
                var categories = DbUtilityFactory.GetDbUtility().GetList(cexp);

                menuList.Add(new MenuDTO()
                {
                    projectID    = i.projectID,
                    projectName  = i.projectName,
                    categoryList = categories.Select <CategoryEntity, MenuItemDTO>(a => new MenuItemDTO()
                    {
                        categoryID   = a.categoryID,
                        categoryName = a.categoryName
                    }).ToList()
                });
            }
            return(new Result <List <MenuDTO> >()
            {
                IsSuccess = true,
                ReturnValue = menuList,
                ReturnMessage = "成功"
            });
        }
Example #11
0
        public void ReturnsSqlString3_ShouldReturnTrue()
        {
            var expectedResult = "SELECT * FROM [Article] WHERE (Article.UserId = '1' )  ";
            var exp            = DbUtilityFactory.GetDbUtility().GetSqlExpression <ArticleEntity>();

            exp.Where(a => a.ArticleDate == DateTime.Now);

            var result = $"SELECT * FROM [{ exp.TableName }] WHERE { exp.WhereStr }";

            Assert.AreEqual(expectedResult, result);
        }
Example #12
0
        public void ReturnsSqlSortString_ShouldReturnTrue()
        {
            var expectedResult = "SELECT * FROM [Article] ORDER BY Article.ArticleDate DESC ";
            var exp            = DbUtilityFactory.GetDbUtility().GetSqlExpression <ArticleEntity>();

            exp.OrderByDescending(a => a.ArticleDate);

            var result = $"SELECT * FROM [{ exp.TableName }] ORDER BY { exp.OrderByStr }";

            Assert.AreEqual(expectedResult, result);
        }
Example #13
0
 public Result <int> Register(RegisterDTO registerInfo)
 {
     #region 参数判断
     if (string.IsNullOrEmpty(registerInfo.nickName))
     {
         return(new Result <int>()
         {
             IsSuccess = false,
             ReturnMessage = "昵称不能为空",
         });
     }
     if (string.IsNullOrEmpty(registerInfo.userName))
     {
         return(new Result <int>()
         {
             IsSuccess = false,
             ReturnMessage = "用户名不能为空",
         });
     }
     if (string.IsNullOrEmpty(registerInfo.password))
     {
         return(new Result <int>()
         {
             IsSuccess = false,
             ReturnMessage = "密码不能为空",
         });
     }
     #endregion
     #region 判重
     var data = DbUtilityFactory.GetDbUtility().GetSingle <UserEntity>(a => a.userName == registerInfo.userName);
     if (data != null)
     {
         return(new Result <int>()
         {
             IsSuccess = false,
             ReturnMessage = "该用户名已存在"
         });
     }
     #endregion
     var user = new UserEntity()
     {
         nickName    = registerInfo.nickName,
         userLevel   = 1,
         userName    = registerInfo.userName,
         passwordMd5 = Security.GetMD5(registerInfo.password),
         userNameMd5 = Security.GetMD5(registerInfo.userName)
     };
     return(new Result <int>()
     {
         IsSuccess = true,
         ReturnMessage = "注册成功",
         ReturnValue = DbUtilityFactory.GetDbUtility().Add <UserEntity>(user)
     });
 }
Example #14
0
        public void LogIoCStartEventToDb(string str)
        {
            var exp = new ServerEventLogEntity()
            {
                description = str,
                eventLevel  = EnumBigEventType.ServerInfo.GetDescription(),
                type        = EnumServerInfoType.IoC.GetDescription(),
                time        = DateTime.Now
            };

            DbUtilityFactory.GetDbUtility().Add(exp);
        }
Example #15
0
        public void LogRequestToDb(HttpRequestMessage r, string responseStr, int operatorID = -999)
        {
            var exp = new RequestLogEntity()
            {
                method     = r.Method.Method,
                url        = r.RequestUri.ToString(),
                operatorID = operatorID,
                time       = DateTime.Now,
                response   = responseStr
            };

            DbUtilityFactory.GetDbUtility().Add(exp);
        }
Example #16
0
        public void LogErrorToDb(Exception e, int operatorID = -999)
        {
            var exp = new ServerEventLogEntity()
            {
                description = e.Message,
                thread      = e.Source,
                time        = DateTime.Now,
                type        = e.GetType().Name,
                eventLevel  = EnumBigEventType.Exception.GetDescription(),
                operatorID  = operatorID
            };

            DbUtilityFactory.GetDbUtility().Add(exp);
        }
Example #17
0
        public Result <ArticleListDTO> GetArticleListByCategoryID(int categoryID)
        {
            var exp = DbUtilityFactory.GetDbUtility().GetSqlExpression <ArticleEntity>();

            exp.Where(a => a.categoryID == categoryID);
            var data = DbUtilityFactory.GetDbUtility().GetList(exp);

            if (data == null)
            {
                return(new Result <ArticleListDTO>()
                {
                    IsSuccess = false,
                    ReturnMessage = "出现错误"
                });
            }
            if (!data.Any())
            {
                return(new Result <ArticleListDTO>()
                {
                    IsSuccess = true,
                    ReturnMessage = "没有找到记录",
                    ReturnValue = new ArticleListDTO()
                    {
                        categoryID = categoryID,
                        categoryName = GetCategoryNameByCategoryID(categoryID).ReturnValue
                    }
                });
            }
            else
            {
                return(new Result <ArticleListDTO>()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = new ArticleListDTO()
                    {
                        categoryID = categoryID,
                        categoryName = GetCategoryNameByCategoryID(categoryID).ReturnValue,
                        ArticleList = data.Select <ArticleEntity, ArticleListItemDTO>(a => new ArticleListItemDTO()
                        {
                            articleCopyright = a.articleCopyright,
                            articleDate = a.articleDate,
                            articleID = a.articleID,
                            articleTitle = a.articleTitle
                        }).ToList()
                    }
                });
            }
        }
Example #18
0
 public Result<int> DeleteProject(int projectID)
 {
     var result = DbUtilityFactory.GetDbUtility().Delete<ProjectEntity>(a => a.projectID == projectID);
     if (result == 1)
     {
         return new Result<int>()
         {
             IsSuccess = true,
             ReturnValue = result,
             ReturnMessage = "删除成功"
         };
     }
     else
     {
         return new Result<int>()
         {
             IsSuccess = false,
             ReturnMessage = "删除失败"
         };
     }
 }
Example #19
0
        public Result <string> GetCategoryNameByCategoryID(int categoryID)
        {
            var result = DbUtilityFactory.GetDbUtility().Scala <CategoryEntity, string>(a => a.categoryName, a => a.categoryID == categoryID);

            if (!String.IsNullOrEmpty(result))
            {
                return(new Result <string>()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = result
                });
            }
            else
            {
                return(new Result <string>()
                {
                    IsSuccess = false,
                    ReturnMessage = "没有找到栏目名称"
                });
            }
        }
Example #20
0
        public Result <UserInfoDTO> CheckLogin(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                return(new Result <UserInfoDTO>()
                {
                    IsSuccess = false,
                    ReturnMessage = "登录失败,用户名或密码不能为空"
                });
            }
            var userInfo    = DbUtilityFactory.GetDbUtility().GetSingle <UserEntity>(a => a.userName == userName);
            var passwordMd5 = Security.GetMD5(password);

            if (userInfo == null || userInfo.passwordMd5 != passwordMd5)
            {
                return(new Result <UserInfoDTO>()
                {
                    IsSuccess = false,
                    ReturnMessage = "登录失败,用户名或密码错误"
                });
            }
            else
            {
                return(new Result <UserInfoDTO>()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = new UserInfoDTO()
                    {
                        cookiePassport = userInfo.userNameMd5 + userInfo.passwordMd5,
                        userName = userName,
                        userID = userInfo.userID,
                        userLevel = userInfo.userLevel,
                        nickName = userInfo.nickName
                    }
                });
            }
        }
Example #21
0
        public Result <int> DeleteCategroy(int categroyID)
        {
            var result = DbUtilityFactory.GetDbUtility().Delete <CategoryEntity>(a => a.categoryID == categroyID);

            if (result == 1)
            {
                return(new Result <int>()
                {
                    IsSuccess = true,
                    ReturnMessage = "成功",
                    ReturnValue = result
                });
            }
            else
            {
                return(new Result <int>()
                {
                    IsSuccess = false,
                    ReturnMessage = "删除失败",
                    ReturnValue = result
                });
            }
        }
Example #22
0
 public void AssSignalRecord_ShouldReturnTrue()
 {
     var expectedResult = "SELECT * FROM [Article] ORDER BY Article.ArticleDate DESC ";
     var article        = new ArticleEntity
     {
         ArticleId = 1,
         //分类ID
         CategoryId = 1,
         //文章标题
         ArticleTitle = "test",
         //文章版权
         ArticleCopyright = "test",
         //文章创建时间
         ArticleDate = DateTime.Now,
         //文章摘要
         ArticleAbstract = "test",
         //文章内容
         ArticleContain = "test",
         //文章所属User
         UserId = 1
     };
     var exp = DbUtilityFactory.GetDbUtility().Add(article);
 }
Example #23
0
        public Result <int> DeleteArticleByArticleID(int articleID)
        {
            var result = DbUtilityFactory.GetDbUtility().Delete <ArticleEntity>(a => a.articleID == articleID);

            if (result == 1)
            {
                return(new Result <int>()
                {
                    ReturnMessage = "删除成功",
                    IsSuccess = true,
                    ReturnValue = result
                });
            }
            else
            {
                return(new Result <int>()
                {
                    ReturnMessage = "删除失败",
                    IsSuccess = false,
                    ReturnValue = result
                });
            }
        }