public IActionResult PictureUpload(PictureDto body)
        {
            using EFCoreContextWrite context = new EFCore.EFCoreContextWrite();
            if (!string.IsNullOrEmpty(body.PictureTitle) && !string.IsNullOrEmpty(body.PictureExplain))
            {
                string token = _httpContext.HttpContext.Request.Headers["Authorization"];

                AuthRedis.GetUserByToken(token, out UserInfo userInfo);
                PictureInfo PictureInfos = new PictureInfo()
                {
                    Id               = SequenceID.GetSequenceID(),
                    CreateTime       = DateTime.Now,
                    Disable          = false,
                    PictureContent   = body.url,
                    UserID           = userInfo.id,
                    LastModifiedTime = DateTime.Now,
                    PictureExplain   = body.PictureExplain,
                    PictureTitle     = body.PictureTitle,
                    RecommendIndex   = body.Index,
                    PictureType      = body.PictureType,
                    PhotoType        = body.PhotoType
                };
                context.Add(PictureInfos);
                context.SaveChanges();
                PictureRedis.Del();
            }
            return(Ok(new ApiResponse()));
        }
Beispiel #2
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            RequestLogs logs = new RequestLogs()
            {
                Id          = SequenceID.GetSequenceID(),
                ApiName     = context.HttpContext.Request.GetEncodedUrl(),
                IP          = context.HttpContext.Connection.RemoteIpAddress.ToString(),
                Headers     = JsonConvert.SerializeObject(context.HttpContext.Request.Headers),
                QueryString = context.HttpContext.Request.QueryString.Value,
                StatusCode  = context.HttpContext.Response.StatusCode,
                Result      = JsonConvert.SerializeObject(context.Result)
            };
            string token = context.HttpContext.Request.Headers["Authorization"];

            if (!string.IsNullOrEmpty(token))
            {
                if (AuthRedis.GetUserByToken(token, out UserInfo userInfo))
                {
                    logs.UID = userInfo.id;
                }
            }
            DBRequestLogs _logs = new DBRequestLogs();

            _logs.Create(logs);
        }
        public Test Add(CreateUpdateTestDto body)
        {
            Test test = new Test()
            {
                Id   = SequenceID.GetSequenceID(),
                Name = body.TestName
            };

            _EFBaseService.Add(test);
            TestRedis.Del();
            return(test);
        }
Beispiel #4
0
        public IActionResult TestEFCoreAndRedisAdd([FromBody] CreateUpdateTestDto body)
        {
            Test test = new Test()
            {
                Id   = SequenceID.GetSequenceID(),
                Name = body.TestName
            };
            var tests = _baseService.Add(test);

            if (tests <= 0)
            {
                return(Ok(new ApiResponse(code: CodeAndMessage.新增失败)));
            }
            return(Ok(new ApiResponse(test)));
        }
        /// <summary>
        /// moreAdd
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public bool moreAdd(int i)
        {
            Test test = new Test();

            for (int j = 0; j <= i; j++)
            {
                test = new Test()
                {
                    Id   = SequenceID.GetSequenceID(),
                    Name = "hangfire"
                };
                _EFBaseService.Add(test);
            }
            TestRedis.Del();
            return(true);
        }
        public IActionResult Register(RegisterDto body)
        {
            var userList = _BaseService.GetListWriteBy <Users>(x => x.Email == body.Email);
            int count    = userList.Where(x => x.CreateTime.AddHours(2) > DateTime.Now).Count();

            if (count > 0)
            {
                return(Ok(new ApiNResponse(code: CodeAndMessage.重复邮箱在俩小时内注册, message: "Repeat email to register within two hours")));
            }
            int userinfo = userList.Where(x => x.Email == body.Email && x.CreateTime.AddHours(2) < DateTime.Now).Count();

            if (userinfo > 0)
            {
                var userlist = userList.Single(x => x.Email == body.Email);

                userlist.CreateTime = DateTime.Now;
                userlist.Count      = userlist.Count + 1;
                _BaseService.ModifyNo(userlist);
                _SendService.SendEmail(body.Email, body.Email, "123456");
            }
            else
            {
                Users users = new Users()
                {
                    Id               = SequenceID.GetSequenceID(),
                    AuthRole         = AuthRole.User,
                    CreateTime       = DateTime.Now,
                    Disable          = false,
                    Email            = body.Email,
                    LastModifiedTime = DateTime.Now,
                    LoginType        = LoginType.LimitWeb,
                    UserName         = body.Email.ToString(),
                    ComPany          = body.ComPany,
                    NickName         = body.NickName,
                    Count            = 1,
                    PassWord         = HashPass.HashString("123456", "MD5")
                };
                _BaseService.Add(users);
                _SendService.SendEmail(body.Email, users.UserName, "123456");
            }
            return(Ok(new ApiResponse()));
        }
        [AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口
        public IActionResult WordsUpLoad(WordDto body)
        {
            string token = _httpContext.HttpContext.Request.Headers["Authorization"];

            AuthRedis.GetUserByToken(token, out UserInfo userInfo);
            using EFCoreContextWrite context = new EFCore.EFCoreContextWrite();
            if (body.Eid == null)
            {
                int count = context.WordInfo.Where(x => x.PictureID == body.id).Count();
                if (count > 0)
                {
                    return(Ok(new ApiResponse(code: CodeAndMessage.已存在对应的资讯文档)));
                }
                WordInfo WordInfos = new WordInfo()
                {
                    Id               = SequenceID.GetSequenceID(),
                    CreateTime       = DateTime.Now,
                    Disable          = false,
                    HtmlContent      = body.HtmlContent,
                    PictureID        = body.id,
                    LastModifiedTime = DateTime.Now,
                    HtmlExplain      = body.HtmlExplain,
                    HtmlTitle        = body.HtmlTitle,
                    AttachedPath     = body.AttachedPath
                };
                context.Add(WordInfos);
                context.SaveChanges();
                WordRedis.Del();
            }
            else
            {
                var WordInfo = context.WordInfo.Single(x => x.Id == body.Eid);
                WordInfo.LastModifiedTime = DateTime.Now;
                WordInfo.HtmlContent      = body.HtmlContent;
                WordInfo.HtmlExplain      = body.HtmlExplain;
                WordInfo.HtmlTitle        = body.HtmlTitle;
                WordInfo.AttachedPath     = body.AttachedPath;
                context.SaveChanges();
                WordRedis.Del();
            }
            return(Ok(new ApiResponse()));
        }
        [AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口
        public IActionResult RegisterFree(RegisterFreeDto body)
        {
            int count = _BaseService.GetListWriteBy <Users>(x => x.UserName == body.UserName).Count();

            if (count > 0)
            {
                return(Ok(new ApiResponse(code: CodeAndMessage.用户名重复)));
            }
            Users users = new Users()
            {
                Id               = SequenceID.GetSequenceID(),
                AuthRole         = AuthRole.User,
                CreateTime       = DateTime.Now,
                Disable          = false,
                Email            = body.Email,
                LastModifiedTime = DateTime.Now,
                LoginType        = LoginType.FreeWeb,
                UserName         = body.UserName,
                PassWord         = HashPass.HashString(body.PassWord, "MD5"),
            };

            _BaseService.Add(users);
            return(Ok(new ApiResponse()));
        }