public IActionResult GetConfig()
        {
            string cacheData = _cacheService.Get("WebSiteConfigCache");

            if (string.IsNullOrEmpty(cacheData))
            {
                var repository = _unitOfWork.GetRepository <Entity.m_WebSiteConfig>();
                var resultData = repository.Query()
                                 .OrderBy(cfg => cfg.ConfigId)
                                 .Select(cfg => new Models.WebSiteConfigResultModel()
                {
                    ConfigId           = cfg.ConfigId.Value,
                    CopyrightText      = cfg.CopyrightText,
                    FilingNo           = cfg.FilingNo,
                    IsLogin            = cfg.IsLogin.Value,
                    IsRegister         = cfg.IsRegister.Value,
                    WebSiteDescription = cfg.WebSiteDescription,
                    WebSiteKeyWord     = cfg.WebSiteKeyWord,
                    WebSiteName        = cfg.WebSiteName,
                    WebSiteTitle       = cfg.WebSiteTitle,
                    WebSiteUrl         = cfg.WebSiteUrl
                })
                                 .FirstOrDefault();
                cacheData = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(resultData)));
                //写入缓存
                _cacheService.Add("WebSiteConfigCache", cacheData);
                return(APIReturnMethod.ReturnSuccess(resultData));
            }
            else
            {
                cacheData = Encoding.UTF8.GetString(Convert.FromBase64String(cacheData.Replace("\"", "")));
                return(APIReturnMethod.ReturnSuccess(JsonConvert.DeserializeObject <Models.WebSiteConfigResultModel>(cacheData)));
            }
        }
        public IActionResult Get([FromRoute] int accountId, [FromRoute] int themeId, [FromRoute] int docsId)
        {
            var accountRepository = _unitOfWork.GetRepository <m_Account>();
            var docRepository     = _unitOfWork.GetRepository <Entity.m_Docs>();
            var docsContentsData  = docRepository.Query()
                                    .Join(accountRepository.Query(), doc => doc.AccountId, acc => acc.AccountId, (doc, acc) => new Models.DocsContentsModel()
            {
                DocsId     = doc.DocsId.Value,
                HeadUrl    = acc.HeadUrl,
                IsShow     = doc.IsShow.Value,
                LastTime   = doc.LastTime.Value,
                PlusCount  = doc.PlusCount.Value,
                NickName   = acc.NickName,
                AppendTime = doc.AppendTime.Value,
                ReadCount  = doc.ReadCount.Value,
                Title      = doc.Title,
                Tags       = doc.Tags,
                AccountId  = doc.AccountId.Value,
                ShortTitle = doc.ShortTitle,
                ThemeId    = doc.ThemeId.Value,
                Contents   = doc.Contents,
                IsAudit    = doc.IsAudit.Value
            })
                                    .Where(q => q.DocsId == docsId && q.ThemeId == themeId && q.AccountId == accountId)
                                    .FirstOrDefault();

            if (docsContentsData != null)
            {
                //更新浏览次数
                _unitOfWork.DbContext.MangoUpdate <Entity.m_Docs>(q => q.ReadCount == q.ReadCount + 1, q => q.DocsId == docsId);
            }
            return(APIReturnMethod.ReturnSuccess(docsContentsData));
        }
Exemple #3
0
        public IActionResult Get([FromRoute] int accountId, [FromRoute] int contentsId)
        {
            var repository        = _unitOfWork.GetRepository <Entity.m_CmsContents>();
            var channelRepository = _unitOfWork.GetRepository <Entity.m_CmsChannel>();
            var accountRepository = _unitOfWork.GetRepository <m_Account>();
            var resultData        = repository.Query()
                                    .Join(accountRepository.Query(), c => c.AccountId, account => account.AccountId, (c, account) => new { c, account })
                                    .Join(channelRepository.Query(), ca => ca.c.ChannelId, channel => channel.ChannelId, (ca, channel) => new Models.ContentsDataModel()
            {
                AccountId   = ca.c.AccountId.Value,
                AnswerCount = ca.c.AnswerCount.Value,
                ChannelId   = ca.c.ChannelId.Value,
                ChannelName = channel.ChannelName,
                ContentsId  = ca.c.ContentsId.Value,
                HeadUrl     = ca.account.HeadUrl,
                LastTime    = ca.c.LastTime.Value,
                NickName    = ca.account.NickName,
                PlusCount   = ca.c.PlusCount.Value,
                PostTime    = ca.c.PostTime.Value,
                ReadCount   = ca.c.ReadCount.Value,
                StateCode   = ca.c.StateCode.Value,
                Title       = ca.c.Title,
                Contents    = ca.c.Contents
            })
                                    .Where(q => q.StateCode == 1 && q.ContentsId == contentsId && q.AccountId == accountId)
                                    .OrderByDescending(q => q.ContentsId)
                                    .FirstOrDefault();

            return(APIReturnMethod.ReturnSuccess(resultData));
        }
        public IActionResult GetNavigation()
        {
            string cacheData = _cacheService.Get("WebSiteNavigationCache");

            if (string.IsNullOrEmpty(cacheData))
            {
                var repository = _unitOfWork.GetRepository <Entity.m_WebSiteNavigation>();
                var resultData = repository.Query()
                                 .OrderBy(nav => nav.SortCount)
                                 .Where(q => q.IsShow == true)
                                 .Select(nav => new Models.WebSiteNavigationDataModel()
                {
                    AppendTime     = nav.AppendTime.Value,
                    IsShow         = nav.IsShow.Value,
                    IsTarget       = nav.IsTarget.Value,
                    LinkUrl        = nav.LinkUrl,
                    NavigationId   = nav.NavigationId.Value,
                    NavigationName = nav.NavigationName,
                    SortCount      = nav.SortCount.Value
                }).ToList();
                cacheData = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(resultData)));
                //写入缓存
                _cacheService.Add("WebSiteNavigationCache", cacheData);
                return(APIReturnMethod.ReturnSuccess(resultData));
            }
            else
            {
                cacheData = Encoding.UTF8.GetString(Convert.FromBase64String(cacheData.Replace("\"", "")));
                //从缓存中获取
                return(APIReturnMethod.ReturnSuccess(JsonConvert.DeserializeObject <List <Models.WebSiteNavigationDataModel> >(cacheData)));
            }
        }
Exemple #5
0
        public IActionResult Get(int channelId, int p)
        {
            var repository        = _unitOfWork.GetRepository <Entity.m_CmsContents>();
            var channelRepository = _unitOfWork.GetRepository <Entity.m_CmsChannel>();
            var accountRepository = _unitOfWork.GetRepository <m_Account>();
            var resultData        = repository.Query()
                                    .Join(accountRepository.Query(), c => c.AccountId, account => account.AccountId, (c, account) => new { c, account })
                                    .Join(channelRepository.Query(), ca => ca.c.ChannelId, channel => channel.ChannelId, (ca, channel) => new Models.ContentsListDataModel()
            {
                AccountId   = ca.c.AccountId.Value,
                AnswerCount = ca.c.AnswerCount.Value,
                ChannelId   = ca.c.ChannelId.Value,
                ChannelName = channel.ChannelName,
                ContentsId  = ca.c.ContentsId.Value,
                HeadUrl     = ca.account.HeadUrl,
                LastTime    = ca.c.LastTime.Value,
                NickName    = ca.account.NickName,
                PlusCount   = ca.c.PlusCount.Value,
                PostTime    = ca.c.PostTime.Value,
                ReadCount   = ca.c.ReadCount.Value,
                StateCode   = ca.c.StateCode.Value,
                Title       = ca.c.Title
            })
                                    .Where(q => q.StateCode == 1 && (channelId > 0 ? q.ChannelId == channelId : q.ChannelId != 0))
                                    .OrderByDescending(q => q.ContentsId)
                                    .Skip(10 * (p - 1))
                                    .Take(10)
                                    .ToList();

            return(APIReturnMethod.ReturnSuccess(resultData));
        }
        public IActionResult Get([FromRoute] int accountId, [FromRoute] int p)
        {
            var repository        = _unitOfWork.GetRepository <Entity.m_DocsTheme>();
            var accountRepository = _unitOfWork.GetRepository <m_Account>();
            var resultData        = repository.Query()
                                    .Join(accountRepository.Query(), t => t.AccountId, acc => acc.AccountId, (t, acc) => new Models.ThemeDataModel()
            {
                ThemeId    = t.ThemeId.Value,
                HeadUrl    = acc.HeadUrl,
                IsShow     = t.IsShow.Value,
                LastTime   = t.LastTime.Value,
                PlusCount  = t.PlusCount.Value,
                NickName   = acc.NickName,
                AppendTime = t.AppendTime.Value,
                ReadCount  = t.ReadCount.Value,
                Title      = t.Title,
                Tags       = t.Tags,
                AccountId  = t.AccountId.Value
            })
                                    .Where(q => q.AccountId == accountId)
                                    .OrderByDescending(q => q.ThemeId)
                                    .Skip(10 * (p - 1))
                                    .Take(10)
                                    .ToList();

            return(APIReturnMethod.ReturnSuccess(resultData));
        }
        public IActionResult Put([FromBody] Models.ThemeEditRequestModel requestModel)
        {
            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题内容"));
            }
            var repository = _unitOfWork.GetRepository <Entity.m_DocsTheme>();

            Entity.m_DocsTheme model = repository.Query().Where(q => q.ThemeId == requestModel.ThemeId).FirstOrDefault();
            if (model == null)
            {
                return(APIReturnMethod.ReturnFailed("您要编辑的文档主题信息不存在!"));
            }
            if (model.AccountId != requestModel.AccountId)
            {
                return(APIReturnMethod.ReturnFailed("您无权对当前的数据进行编辑操作!"));
            }
            model.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.LastTime    = DateTime.Now;
            model.Title       = HtmlFilter.StripHtml(requestModel.Title);
            model.VersionText = "";

            repository.Update(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
        public IActionResult Get([FromRoute] int accountId, [FromRoute] int themeId, [FromRoute] int p)
        {
            var docRepository = _unitOfWork.GetRepository <Entity.m_Docs>();
            var docListData   = docRepository.Query()
                                .Where(q => q.ThemeId == themeId && q.IsShow == true && q.AccountId == accountId)
                                .OrderByDescending(q => q.DocsId)
                                .Select(q => new Models.DocumentDataModel()
            {
                DocsId     = q.DocsId.Value,
                ShortTitle = q.ShortTitle,
                Title      = q.Title,
                ThemeId    = q.ThemeId.Value,
                IsShow     = q.IsShow.Value,
                AppendTime = q.AppendTime,
                PlusCount  = q.PlusCount,
                ReadCount  = q.ReadCount,
                AccountId  = q.AccountId
            })
                                .OrderByDescending(q => q.DocsId)
                                .Skip(10 * (p - 1))
                                .Take(10)
                                .ToList();

            return(APIReturnMethod.ReturnSuccess(docListData));
        }
        public IActionResult Post([FromBody] Models.ThemeCreateRequestModel requestModel)
        {
            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题内容"));
            }
            Entity.m_DocsTheme model = new Entity.m_DocsTheme();
            model.AppendTime  = DateTime.Now;
            model.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.IsShow      = true;
            model.LastTime    = DateTime.Now;
            model.PlusCount   = 0;
            model.ReadCount   = 0;
            model.Tags        = "";
            model.Title       = HtmlFilter.StripHtml(requestModel.Title);
            model.AccountId   = requestModel.AccountId;
            model.VersionText = "";
            var repository = _unitOfWork.GetRepository <Entity.m_DocsTheme>();

            repository.Insert(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #10
0
        public IActionResult Get()
        {
            var repository = _unitOfWork.GetRepository <Entity.m_CmsChannel>();
            var resultData = repository.Query().OrderBy(q => q.SortCount).ToList();

            return(APIReturnMethod.ReturnSuccess(resultData));
        }
        public IActionResult GetUserTheme([FromRoute] int accountId, [FromRoute] int themeId)
        {
            var accountRepository = _unitOfWork.GetRepository <m_Account>();
            var themeRepository   = _unitOfWork.GetRepository <Entity.m_DocsTheme>();
            var themeData         = themeRepository.Query()
                                    .Join(accountRepository.Query(), doc => doc.AccountId, acc => acc.AccountId, (doc, acc) => new Models.ThemeDataModel()
            {
                ThemeId    = doc.ThemeId.Value,
                HeadUrl    = acc.HeadUrl,
                IsShow     = doc.IsShow.Value,
                LastTime   = doc.LastTime.Value,
                PlusCount  = doc.PlusCount.Value,
                NickName   = acc.NickName,
                AppendTime = doc.AppendTime.Value,
                ReadCount  = doc.ReadCount.Value,
                Title      = doc.Title,
                Tags       = doc.Tags,
                AccountId  = doc.AccountId.Value,
                Contents   = doc.Contents
            })
                                    .Where(q => q.ThemeId == themeId && q.AccountId == accountId)
                                    .OrderByDescending(q => q.ThemeId)
                                    .FirstOrDefault();

            return(APIReturnMethod.ReturnSuccess(themeData));
        }
Exemple #12
0
        public IActionResult Document(Models.EditDocumentRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档内容"));
            }
            var repository = _unitOfWork.GetRepository <Entity.m_Docs>();

            Entity.m_Docs model = repository.Query().Where(q => q.DocsId == requestModel.DocsId).FirstOrDefault();
            if (model == null)
            {
                return(APIReturnMethod.ReturnFailed("您要编辑的文档内容信息不存在!"));
            }
            if (model.AccountId != requestModel.AccountId)
            {
                return(APIReturnMethod.ReturnFailed("您无权对当前的数据进行编辑操作!"));
            }
            model.Contents   = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.LastTime   = DateTime.Now;
            model.Title      = HtmlFilter.StripHtml(requestModel.Title);
            model.ShortTitle = HtmlFilter.StripHtml(requestModel.ShortTitle);

            repository.Update(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #13
0
        public IActionResult Password(Models.PasswordUpdateRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (string.IsNullOrEmpty(requestModel.Password))
            {
                return(APIReturnMethod.ReturnFailed("请输入您的原登录密码!"));
            }
            if (string.IsNullOrEmpty(requestModel.NewPassword))
            {
                return(APIReturnMethod.ReturnFailed("请输入您的新登录密码!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query().Where(q => q.AccountId == requestModel.AccountId && q.Password == TextHelper.MD5Encrypt(requestModel.Password)).FirstOrDefault();

            if (accountData == null)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的原登录密码!"));
            }
            accountData.Password = TextHelper.MD5Encrypt(requestModel.NewPassword);
            repository.Update(accountData);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #14
0
        public IActionResult Document(Models.DocsContentsCreateRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);
            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档内容"));
            }
            Entity.m_Docs model = new Entity.m_Docs();
            model.AppendTime  = DateTime.Now;
            model.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.IsShow      = true;
            model.LastTime    = DateTime.Now;
            model.PlusCount   = 0;
            model.ReadCount   = 0;
            model.Tags        = "";
            model.Title       = HtmlFilter.StripHtml(requestModel.Title);
            model.AccountId   = requestModel.AccountId;
            model.VersionText = "";
            model.ThemeId     = requestModel.ThemeId;
            model.ShortTitle  = HtmlFilter.StripHtml(requestModel.ShortTitle);
            model.IsAudit     = true;
            var repository = _unitOfWork.GetRepository <Entity.m_Docs>();

            repository.Insert(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #15
0
        public IActionResult Index(Models.ReleaseRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (string.IsNullOrEmpty(requestModel.Title) || requestModel.Title == "")
            {
                return(APIReturnMethod.ReturnFailed("标题不能为空"));
            }
            if (string.IsNullOrEmpty(requestModel.Contents) || requestModel.Contents == "")
            {
                return(APIReturnMethod.ReturnFailed("内容不能为空"));
            }
            //
            Entity.m_CmsContents entity = new Entity.m_CmsContents();
            entity.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            entity.ImgUrl      = string.Empty;
            entity.StateCode   = 1;
            entity.PostTime    = DateTime.Now;
            entity.PlusCount   = 0;
            entity.LastTime    = DateTime.Now;
            entity.Tags        = "";
            entity.ReadCount   = 0;
            entity.Title       = requestModel.Title;
            entity.AccountId   = requestModel.AccountId;
            entity.AnswerCount = 0;
            entity.ChannelId   = requestModel.ChannelId;
            var repository = _unitOfWork.GetRepository <Entity.m_CmsContents>();

            repository.Insert(entity);
            int resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #16
0
        public IActionResult Index(Models.ContentsEditRequestModel requestModel)
        {
            if (string.IsNullOrEmpty(requestModel.Title) || requestModel.Title == "")
            {
                return(APIReturnMethod.ReturnFailed("标题不能为空"));
            }
            if (string.IsNullOrEmpty(requestModel.Contents) || requestModel.Contents == "")
            {
                return(APIReturnMethod.ReturnFailed("内容不能为空"));
            }
            var repository = _unitOfWork.GetRepository <Entity.m_CmsContents>();

            //
            Entity.m_CmsContents entity = repository.Query().Where(q => q.ContentsId == requestModel.ContentsId).FirstOrDefault();
            entity.Contents   = requestModel.Contents;//Framework.Core.HtmlFilter.SanitizeHtml(model.Contents);
            entity.LastTime   = DateTime.Now;
            entity.Title      = requestModel.Title;
            entity.ContentsId = requestModel.ContentsId;
            entity.ChannelId  = requestModel.ChannelId;

            repository.Update(entity);
            int resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
        /// <summary>
        /// 邮箱验证码发送
        /// </summary>
        /// <param name="email"></param>
        /// <param name="ticket"></param>
        /// <param name="randstr"></param>
        /// <returns></returns>
        public async Task <IActionResult> SendEmailValidateCode(string email, string ticket, string randstr)
        {
            string userIP = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            bool   tencentCaptchaResult = _tencentCaptcha.QueryTencentCaptcha(ticket, randstr, userIP);

            if (!tencentCaptchaResult)
            {
                return(APIReturnMethod.ReturnFailed("你的验证操作没有通过!"));
            }
            Regex regex = new Regex(@"([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)");

            if (!regex.IsMatch(email))
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的电子邮箱!"));
            }
            var repository = _unitOfWork.GetRepository <m_Account>();

            if (repository.Query().Where(q => q.AccountName == email).Count() > 0)
            {
                return(APIReturnMethod.ReturnFailed("该电子邮箱已经注册,请勿重复注册!"));
            }

            //邮件发送处理
            string emailCode = new Random().Next(101326, 985963).ToString();

            _memoryCache.Set <string>(email, emailCode);

            string messageContent = string.Format("感谢您的注册,您的验证码为:{0},您可以继续完成您的注册!", emailCode);
            string subject        = "51Core技术网用户注册验证码邮件";

            bool sendResult = await _emailService.SendEmail(email, subject, messageContent);

            //邮件发送内容保存
            m_Sms model = new m_Sms();

            model.Contents = string.Format("邮箱验证码为:{0} 服务器返回结果:{1}", emailCode, sendResult);
            model.IsOk     = sendResult;
            model.Phone    = email;
            model.SendIP   = userIP;
            model.SendTime = DateTime.Now;
            var smsRepository = _unitOfWork.GetRepository <m_Sms>();

            smsRepository.Insert(model);
            _unitOfWork.SaveChanges();
            if (sendResult)
            {
                return(APIReturnMethod.ReturnSuccess("注册验证码发送成功,请注意查收!"));
            }
            return(APIReturnMethod.ReturnFailed("注册验证码发送失败,请稍后再试!"));
        }
Exemple #18
0
        public IActionResult Index(Models.AccountLoginRequestModel requestModel)
        {
            if (string.IsNullOrEmpty(requestModel.AccountName) || requestModel.AccountName == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录账号!"));
            }
            if (string.IsNullOrEmpty(requestModel.Password) || requestModel.Password == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录密码!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query()
                              .Where(q => q.AccountName == requestModel.AccountName && q.Password == TextHelper.MD5Encrypt(requestModel.Password.Trim()))
                              .Select(q => new Models.AccountDataModel()
            {
                AccountId     = q.AccountId.Value,
                AccountName   = q.AccountName,
                AddressInfo   = q.AddressInfo,
                Birthday      = q.Birthday,
                Email         = q.Email,
                GroupId       = q.GroupId.Value,
                HeadUrl       = q.HeadUrl,
                LastLoginDate = q.LastLoginDate.Value,
                NickName      = q.NickName,
                Phone         = q.Phone,
                RegisterDate  = q.RegisterDate.Value,
                Sex           = q.Sex,
                StateCode     = q.StateCode.Value,
                Tags          = q.Tags
            })
                              .FirstOrDefault();

            if (accountData == null)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的账号与密码!"));
            }
            if (accountData.StateCode == 0)
            {
                return(APIReturnMethod.ReturnFailed("该账号已经被禁止登陆!"));
            }
            //将登陆的用户Id存储到会话中
            HttpContext.Session.SetInt32("AccountId", accountData.AccountId);
            HttpContext.Session.SetInt32("RoleId", accountData.GroupId);
            HttpContext.Session.SetString("AccountName", accountData.AccountName);
            HttpContext.Session.SetString("NickName", accountData.NickName);
            HttpContext.Session.SetString("HeadUrl", accountData.HeadUrl);
            HttpContext.Session.SetString("AccountLoginData", JsonConvert.SerializeObject(accountData));
            return(APIReturnMethod.ReturnSuccess(accountData));
        }
Exemple #19
0
        public IActionResult Get(string fileName)
        {
            string filePath   = $"/{DateTime.Now.Year}/{DateTime.Now.Month}/{System.Guid.NewGuid().ToString().Replace("-", "")}/{Path.GetExtension(fileName)}";
            string timeStamp  = _upyunService.GetTimeStamp();
            string policy     = _upyunService.GetPolicy(filePath, timeStamp);
            var    resultData = new
            {
                Expiration = timeStamp,
                Path       = filePath,
                Policy     = policy,
                Signature  = _upyunService.GetSignature(policy)
            };

            return(APIReturnMethod.ReturnSuccess(resultData));
        }
Exemple #20
0
        public IActionResult Index(Models.AccountRegisterRequestModel requestModel)
        {
            string Result     = string.Empty;
            var    repository = _unitOfWork.GetRepository <m_Account>();
            var    codeCache  = _memoryCache.Get <string>(requestModel.AccountName);

            if (codeCache == null)
            {
                return(APIReturnMethod.ReturnFailed("该账号与通过验证的账号不一致"));
            }
            if (requestModel.ValidateCode != codeCache)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的注册验证码!"));
            }

            if (repository.Query().Where(q => q.AccountName == requestModel.AccountName).Count() > 0)
            {
                return(APIReturnMethod.ReturnFailed("该账号已经注册过!"));
            }
            //注册新用户
            m_Account entity = new m_Account();

            entity.HeadUrl       = "/images/avatar.png";
            entity.GroupId       = 1;
            entity.StateCode     = 1;
            entity.LastLoginDate = DateTime.Now;
            entity.NickName      = requestModel.NickName;
            entity.Password      = TextHelper.MD5Encrypt(requestModel.Password);
            entity.Phone         = "";
            entity.RegisterDate  = DateTime.Now;
            entity.AccountName   = requestModel.AccountName;
            entity.Email         = "";
            entity.AddressInfo   = "";
            entity.Birthday      = "";
            entity.Sex           = "男";
            entity.Tags          = "";
            repository.Insert(entity);
            var resultCount = _unitOfWork.SaveChanges();

            if (resultCount > 0)
            {
                return(APIReturnMethod.ReturnSuccess("恭喜您,您的账户已经注册成功!"));
            }
            return(APIReturnMethod.ReturnFailed("抱歉,您的注册失败,请稍后再尝试!"));
        }
        public IActionResult Get([FromRoute] int id, bool isGood)
        {
            var docRepository = _unitOfWork.GetRepository <Entity.m_Docs>();
            var docListData   = docRepository.Query()
                                .Where(q => q.ThemeId == id && q.IsShow == true)
                                .OrderByDescending(q => q.DocsId)
                                .Select(q => new Models.DocumentDataModel()
            {
                DocsId     = q.DocsId.Value,
                ShortTitle = q.ShortTitle,
                Title      = q.Title,
                ThemeId    = q.ThemeId.Value,
                IsShow     = q.IsShow.Value
            })
                                .ToList();

            return(APIReturnMethod.ReturnSuccess(docListData));
        }
Exemple #22
0
        public IActionResult Post([FromBody] Models.LoginRequestModel requestModel)
        {
            if (string.IsNullOrEmpty(requestModel.AccountName) || requestModel.AccountName == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录账号!"));
            }
            if (string.IsNullOrEmpty(requestModel.Password) || requestModel.Password == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录密码!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query()
                              .Where(q => q.AccountName == requestModel.AccountName && q.Password == TextHelper.MD5Encrypt(requestModel.Password.Trim()))
                              .Select(q => new Models.AcountDataModel()
            {
                AccountId     = q.AccountId.Value,
                AccountName   = q.AccountName,
                AddressInfo   = q.AddressInfo,
                Birthday      = q.Birthday,
                Email         = q.Email,
                GroupId       = q.GroupId.Value,
                HeadUrl       = q.HeadUrl,
                LastLoginDate = q.LastLoginDate.Value,
                NickName      = q.NickName,
                Phone         = q.Phone,
                RegisterDate  = q.RegisterDate.Value,
                Sex           = q.Sex,
                StateCode     = q.StateCode.Value,
                Tags          = q.Tags
            })
                              .FirstOrDefault();

            if (accountData == null)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的账号与密码!"));
            }
            if (accountData.StateCode == 0)
            {
                return(APIReturnMethod.ReturnFailed("该账号已经被禁止登陆!"));
            }
            return(APIReturnMethod.ReturnSuccess(accountData));
        }
Exemple #23
0
        public IActionResult Get(string type, int count)
        {
            var repository        = _unitOfWork.GetRepository <Entity.m_CmsContents>();
            var channelRepository = _unitOfWork.GetRepository <Entity.m_CmsChannel>();
            var accountRepository = _unitOfWork.GetRepository <m_Account>();
            var query             = repository.Query()
                                    .Join(accountRepository.Query(), c => c.AccountId, account => account.AccountId, (c, account) => new { c, account })
                                    .Join(channelRepository.Query(), ca => ca.c.ChannelId, channel => channel.ChannelId, (ca, channel) => new Models.ContentsListDataModel()
            {
                AccountId   = ca.c.AccountId.Value,
                AnswerCount = ca.c.AnswerCount.Value,
                ChannelId   = ca.c.ChannelId.Value,
                ChannelName = channel.ChannelName,
                ContentsId  = ca.c.ContentsId.Value,
                HeadUrl     = ca.account.HeadUrl,
                LastTime    = ca.c.LastTime.Value,
                NickName    = ca.account.NickName,
                PlusCount   = ca.c.PlusCount.Value,
                PostTime    = ca.c.PostTime.Value,
                ReadCount   = ca.c.ReadCount.Value,
                StateCode   = ca.c.StateCode.Value,
                Title       = ca.c.Title
            })
                                    .Where(q => q.StateCode == 1);

            List <Models.ContentsListDataModel> resultData = new List <Models.ContentsListDataModel>();

            switch (type)
            {
            case "new":
                resultData = query.OrderByDescending(q => q.ContentsId).Take(count).ToList();
                break;

            case "hot":
                resultData = query.OrderByDescending(q => q.ReadCount).Where(q => q.PostTime >= DateTime.Now.AddDays(-7)).Take(10).ToList();
                break;
            }
            return(APIReturnMethod.ReturnSuccess(resultData));
        }
Exemple #24
0
        public IActionResult Information(Models.InformationUpdateRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (string.IsNullOrEmpty(requestModel.InformationValue))
            {
                return(APIReturnMethod.ReturnFailed("请输入待修改项的值!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query().Where(q => q.AccountId == requestModel.AccountId).FirstOrDefault();

            switch (requestModel.InformationType)
            {
            case 3:
                accountData.Tags = requestModel.InformationValue;
                break;

            case 4:
                accountData.AddressInfo = requestModel.InformationValue;
                break;

            case 5:
                accountData.Sex = requestModel.InformationValue;
                break;

            case 1:
                accountData.NickName = requestModel.InformationValue;
                break;

            case 2:
                accountData.HeadUrl = requestModel.InformationValue;
                break;
            }
            repository.Update(accountData);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #25
0
 public IActionResult Get()
 {
     return(APIReturnMethod.ReturnSuccess());
 }
Exemple #26
0
        public IActionResult Theme(Models.ThemePlusRequestModel requestModel)
        {
            int accountId         = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);
            var messageRepository = _unitOfWork.GetRepository <m_Message>();
            var plusRepository    = _unitOfWork.GetRepository <m_AccountPlusRecords>();
            var plusCount         = plusRepository.Query().Where(q => q.AccountId == accountId && q.ObjectId == requestModel.ThemeId && q.RecordsType == 10).Select(q => q.RecordsId).Count();

            int resultCount = 0;

            using (var tran = _unitOfWork.BeginTransaction())
            {
                try
                {
                    if (plusCount > 0)
                    {
                        //存在则撤回点赞记录
                        _unitOfWork.DbContext.MangoRemove <m_AccountPlusRecords>(q => q.ObjectId == requestModel.ThemeId && q.AccountId == accountId && q.RecordsType == 10);
                        //
                        _unitOfWork.DbContext.MangoUpdate <Entity.m_DocsTheme>(q => q.PlusCount == q.PlusCount - 1, q => q.ThemeId == requestModel.ThemeId);
                        resultCount = -1;
                    }
                    else
                    {
                        //添加新点赞记录
                        m_AccountPlusRecords model = new m_AccountPlusRecords();
                        model.ObjectId    = requestModel.ThemeId;
                        model.AppendTime  = DateTime.Now;
                        model.RecordsType = 10;
                        model.AccountId   = accountId;
                        plusRepository.Insert(model);
                        //
                        _unitOfWork.DbContext.MangoUpdate <Entity.m_DocsTheme>(q => q.PlusCount == q.PlusCount + 1, q => q.ThemeId == requestModel.ThemeId);
                        //
                        //消息通知
                        m_Message message = new m_Message();
                        message.AppendAccountId = accountId;
                        message.Contents        = Core.Common.MessageHtml.GetMessageContent(HttpContext.Session.GetString("NickName"), requestModel.ThemeId, requestModel.Title, 10, 0);
                        message.IsRead          = false;
                        message.MessageType     = 10;
                        message.ObjectId        = requestModel.ThemeId;
                        message.PostTime        = DateTime.Now;
                        message.AccountId       = requestModel.ToAccountId;

                        messageRepository.Insert(message);
                        resultCount = 1;
                    }
                    _unitOfWork.SaveChanges();
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    resultCount = 0;
                }
            }
            if (resultCount > 0)
            {
                var    messageCount = messageRepository.Query().Where(q => q.AccountId == requestModel.ToAccountId && q.IsRead == false).Select(q => q.MessageId).Count();
                string sendMsg      = $"{accountId}#{messageCount}";
                //发送消息
                _rabbitMQService.BasicPublish("message", System.Text.Encoding.UTF8.GetBytes(sendMsg));
            }
            return(APIReturnMethod.ReturnSuccess(resultCount));
        }