Example #1
0
        public IResult DeleteArticle([FromBody] int id)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;

            try
            {
                var result = _article.Delete(id, userInfo);
                resultcode    = result.ResultCode;
                resultmessage = result.Message;
                resultval     = result.IsSuccess;
                if (resultval)
                {
                    if (_memcache.TryGetValue("Article" + id, out Articles val))
                    {
                        _memcache.Remove("Article" + id);
                    }
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "DeleteArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), _httpContext.HttpContext.Request.Path, userInfo.ClientIp, userInfo.UsrId);
            }
            return(new Result(resultval, resultmessage, resultcode));
        }
Example #2
0
        public IObjResult <Writers> GetById(int id, AutUserInfo userInfo)
        {
            string  _resultMessage = string.Empty;
            int     _code          = StaticValues.InfoCode;
            bool    _resultval     = false;
            Writers _resultentity  = null;

            try
            {
                _resultentity = _repos.Get(x => x.Id == id && x.Active && !x.Deleted);
                if (_resultentity != null)
                {
                    _code          = StaticValues.SuccessCode;
                    _resultMessage = StaticValues.SuccessMessage;
                    _resultval     = true;
                }
                else
                {
                    _code          = StaticValues.ErrorNullObjCode;
                    _resultMessage = StaticValues.ErrorNullObjMessage;
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "GetById", "WritersManager", Enum.GetName(typeof(LayerInfo), 2), "", userInfo.ClientIp, userInfo.UsrId);
                _code          = StaticValues.ErrorCode;
                _resultMessage = StaticValues.ErrorMessage;
            }
            return(new ObjResult <Writers>(_resultval, _resultMessage, _code, _resultentity));
        }
Example #3
0
        public IResult UpdateComments([FromBody] Comments model)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;

            try
            {
                model.ModifiedDate   = DateTime.Now;
                model.ModifiedUserId = userInfo.UsrId;
                var result = _comment.Update(model, userInfo);
                resultcode    = result.ResultCode;
                resultmessage = result.Message;
                resultval     = result.IsSuccess;
                if (resultval)
                {
                    if (_memcache.TryGetValue("Comments" + model.Id, out Comments val))
                    {
                        _memcache.Remove("Comments" + model.Id);
                        _memcache.Set <Comments>("Comments" + model.Id, model);
                    }
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "UpdateComments", "CommentsController", Enum.GetName(typeof(LayerInfo), 1), _httpContext.HttpContext.Request.Path, userInfo.ClientIp, userInfo.UsrId);
            }
            return(new Result(resultval, resultmessage, resultcode));
        }
Example #4
0
        public IObjResult <AccessToken> CreateToken(AutUserInfo userInfo)
        {
            string      _resultMessage;
            int         _code      = StaticValues.InfoCode;
            bool        _resultval = false;
            AccessToken token      = null;

            try
            {
                _log.Add(userInfo.SessId, "Kullanıcı için token oluşturma işlemi başlamıştır", "CreateToken", "UserManager", Enum.GetName(typeof(Layers.LayerInfo), 2), "", userInfo.ClientIp, userInfo.UsrId);
                token = _tokenHelper.CreateToken(userInfo);
                if (token != null)
                {
                    _resultMessage = StaticValues.SuccessMessage;
                    _code          = StaticValues.SuccessCode;
                    _resultval     = true;
                }
                else
                {
                    _resultMessage = StaticValues.ErrorMessage;
                    _code          = StaticValues.ErrorCode;
                }
                _log.Add(userInfo.SessId, "Kullanıcı için token oluşturma işlemi tamamlanmıştır.Sonuç=" + (_resultval ? "Başarılı" : "Hatalı"), "CreateToken", "UserManager", Enum.GetName(typeof(Layers.LayerInfo), 2), "", userInfo.ClientIp, userInfo.UsrId);
            }
            catch (Exception ex)
            {
                _resultMessage = StaticValues.ErrorMessage;
                _code          = StaticValues.ErrorCode;
                _log.Add(userInfo.SessId, "Kullanıcı bilgileri getirme esnasında bir sorun ile karşılaşıldı. Hata içeriği=" + ex.ToString(), "CreateToken", "UserManager", Enum.GetName(typeof(Layers.LayerInfo), 2), "", userInfo.ClientIp, userInfo.UsrId);
            }
            return(new ObjResult <AccessToken>(_resultval, _resultMessage, _code, token));
        }
Example #5
0
        public IResult Delete(int id, AutUserInfo userInfo)
        {
            string _resultMessage = string.Empty;
            int    _code          = StaticValues.InfoCode;
            bool   _resultval     = false;

            try
            {
                Writers model = _repos.Get(x => x.Id == id);
                if (model != null)
                {
                    model.Active         = false;
                    model.Deleted        = true;
                    model.ModifiedDate   = DateTime.Now;
                    model.ModifiedUserId = userInfo.UsrId;
                    _repos.Update(model);
                    _code          = StaticValues.SuccessCode;
                    _resultMessage = StaticValues.SuccessMessage;
                    _resultval     = true;
                }
                else
                {
                    _code          = StaticValues.ErrorNullObjCode;
                    _resultMessage = StaticValues.ErrorNullObjMessage;
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "Delete", "WritersManager", Enum.GetName(typeof(LayerInfo), 2), "", userInfo.ClientIp, userInfo.UsrId);
                _code          = StaticValues.ErrorCode;
                _resultMessage = StaticValues.ErrorMessage;
            }
            return(new Result(_resultval, _resultMessage, _code));
        }
Example #6
0
        public IObjResult <Writers> GetWriter(int id)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;
            Writers     resultobj     = null;

            try
            {
                if (!_memcache.TryGetValue <Writers>("Writer" + id, out resultobj))
                {
                    var result = _writer.GetById(id, userInfo);
                    resultcode    = result.ResultCode;
                    resultmessage = result.Message;
                    resultval     = result.IsSuccess;
                    resultobj     = result.Object;
                    if (resultval)
                    {
                        _memcache.Set <Writers>("Writer" + id, resultobj);
                    }
                }
                else
                {
                    resultcode    = StaticValues.SuccessCode;
                    resultmessage = StaticValues.SuccessMessage;
                    resultval     = true;
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "GetWriter", "WriterController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            return(new ObjResult <Writers>(resultval, resultmessage, resultcode, resultobj));
        }
Example #7
0
        public IResult RemoveCache([FromQuery] string key)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;

            try
            {
                if (_memcache.TryGetValue(key, out object val))
                {
                    _memcache.Remove(key);
                    resultmessage = StaticValues.SuccessMessage;
                    resultcode    = StaticValues.SuccessCode;
                    resultval     = true;
                }
                else
                {
                    resultmessage = StaticValues.ErrorNullObjMessage;
                    resultcode    = StaticValues.ErrorNullObjCode;
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "RemoveCache", "CacheController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            return(new Result(resultval, resultmessage, resultcode));
        }
Example #8
0
        private IEnumerable <Claim> SetClaims(AutUserInfo info)
        {
            List <Claim> claims = new List <Claim>();

            claims.AddUserIdentifier(info.UsrId.ToString());
            return(claims);
        }
Example #9
0
        public IResult Update(Commenters model, AutUserInfo userInfo)
        {
            string _resultMessage = string.Empty;
            int    _code          = StaticValues.InfoCode;
            bool   _resultval     = false;

            try
            {
                Commenters entity = _repos.Get(x => x.Id == model.Id);
                if (entity != null)
                {
                    entity.ModifiedDate   = DateTime.Now;
                    entity.ModifiedUserId = userInfo.UsrId;
                    _repos.Update(model);
                    _code          = StaticValues.SuccessCode;
                    _resultMessage = StaticValues.SuccessMessage;
                    _resultval     = true;
                }
                else
                {
                    _code          = StaticValues.ErrorCode;
                    _resultMessage = StaticValues.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "Add", "CommentersManager", Enum.GetName(typeof(LayerInfo), 2), "", userInfo.ClientIp, userInfo.UsrId);
                _code          = StaticValues.ErrorCode;
                _resultMessage = StaticValues.ErrorMessage;
            }
            return(new Result(_resultval, _resultMessage, _code));
        }
Example #10
0
        public JwtSecurityToken CreateJwtSecurityToken(TokenOptions tokenOptions, AutUserInfo userInfo, SigningCredentials signingCredentials)
        {
            var jwt = new JwtSecurityToken(
                issuer: _tokenOptions.Issuer,
                audience: _tokenOptions.Audience,
                notBefore: DateTime.Now,
                expires: _accessTokenExpireDate,
                signingCredentials: signingCredentials,
                claims: SetClaims(userInfo)
                );

            return(jwt);
        }
Example #11
0
        public AccessToken CreateToken(AutUserInfo userInfo)
        {
            var securitykey        = SecurityKeyHelper.CreateSecurityKey(_tokenOptions.SecurityKey);
            var singingCredentials = Encryption.CreateSigningCredentials(securitykey);
            var jwt = CreateJwtSecurityToken(_tokenOptions, userInfo, singingCredentials);
            var _jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
            var token = _jwtSecurityTokenHandler.WriteToken(jwt);

            return(new AccessToken
            {
                Token = token,
                Expiration = _accessTokenExpireDate
            });
        }
Example #12
0
        public IObjResult <Articles> GetArticle(int id)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;
            Articles    resultobj     = null;

            try
            {
                _memcache.TryGetValue <Articles>("Article" + id, out resultobj);
                if (resultobj == null)
                {
                    var result = _article.GetById(id, userInfo);
                    resultcode    = result.ResultCode;
                    resultmessage = result.Message;
                    resultval     = result.IsSuccess;
                    resultobj     = result.Object;
                    if (result.IsSuccess && result.Object != null)
                    {
                        var cacheExpOptions = new MemoryCacheEntryOptions
                        {
                            AbsoluteExpiration = DateTime.Now.AddMinutes(10),
                            Priority           = CacheItemPriority.Normal
                        };
                        _memcache.Set <Articles>("Article" + id, resultobj, cacheExpOptions);
                    }
                }
                else
                {
                    resultobj.Title += "-Mem";
                    resultcode       = StaticValues.SuccessCode;
                    resultmessage    = StaticValues.SuccessMessage;
                    resultval        = true;
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "GetArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            return(new ObjResult <Articles>(resultval, resultmessage, resultcode, resultobj));
        }
Example #13
0
        public IResult UpdateWriter([FromBody] Writers model)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;

            try
            {
                var result = _writer.Update(model, userInfo);
                resultcode    = result.ResultCode;
                resultmessage = result.Message;
                resultval     = result.IsSuccess;
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "UpdateWriter", "WriterController", Enum.GetName(typeof(LayerInfo), 1), _httpContext.HttpContext.Request.Path, userInfo.ClientIp, userInfo.UsrId);
            }
            return(new Result(resultval, resultmessage, resultcode));
        }
Example #14
0
        public IResult Add(Writers model, AutUserInfo userInfo)
        {
            string _resultMessage = string.Empty;
            int    _code          = StaticValues.InfoCode;
            bool   _resultval     = false;

            try
            {
                _repos.Add(model);
                _code          = StaticValues.SuccessCode;
                _resultMessage = StaticValues.SuccessMessage;
                _resultval     = true;
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "Add", "WritersManager", Enum.GetName(typeof(LayerInfo), 2), "", userInfo.ClientIp, userInfo.UsrId);
                _code          = StaticValues.ErrorCode;
                _resultMessage = StaticValues.ErrorMessage;
                _resultval     = false;
            }
            return(new Result(_resultval, _resultMessage, _code));
        }
Example #15
0
        public IObjResult <AutUserInfo> GetUser(string email, string password, string clientip, string sessionid)
        {
            string      _resultMessage;
            int         _code      = StaticValues.InfoCode;
            bool        _resultval = false;
            AutUserInfo usrInfo    = new AutUserInfo
            {
                ClientIp = clientip,
                SessId   = sessionid,
                UsrId    = StaticValues.DefUserId
            };

            try
            {
                _log.Add(sessionid, "Kullanıcı bilgileri getirme işlemi başlamıştır. Ekli parametreler ile başlamıştır. email=" + email + ",password=Güvenlik sebebiyle şifre kaydedilmemektedir", "GetUser", "UserManager", Enum.GetName(typeof(Layers.LayerInfo), 2), "", clientip, usrInfo.UsrId);
                Users user = _users.Get(x => x.Email == email && x.Password == password && x.Active && !x.Deleted);
                if (user != null)
                {
                    _resultMessage = StaticValues.SuccessMessage;
                    _resultval     = true;
                    _code          = StaticValues.SuccessCode;
                    usrInfo.UsrId  = user.Id;
                }
                else
                {
                    _resultMessage = StaticValues.ErrorUserAuthMessage;
                    _resultval     = false;
                    _code          = StaticValues.ErrorUserAuthCode;
                }
                _log.Add(sessionid, "Kullanıcı bilgileri getirme işlemi tamamlanmıştır. Sonuç=" + (_resultval ? "Başarılı" : "Hatalı"), "GetUser", "UserManager", Enum.GetName(typeof(Layers.LayerInfo), 2), "", clientip, usrInfo.UsrId);
            }
            catch (Exception ex)
            {
                _resultMessage = StaticValues.ErrorMessage;
                _code          = StaticValues.ErrorCode;
                _log.Add(sessionid, "Kullanıcı bilgileri getirme esnasında bir sorun ile karşılaşıldı. Hata içeriği=" + ex.ToString(), "GetUser", "UserManager", Enum.GetName(typeof(Layers.LayerInfo), 2), "", clientip, usrInfo.UsrId);
            }
            return(new ObjResult <AutUserInfo>(_resultval, _resultMessage, _code, usrInfo));
        }
Example #16
0
        public IResult AddArticle([FromBody] Articles model)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;

            try
            {
                _logs.Add(userInfo.SessId, string.Format("Makale ekleme işlemi ekli parametreler ile başlamıştır.{0}", Reflections.GetModelPropertyValues <Articles>(model)), "AddArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
                var result = _article.Add(model, userInfo);
                resultcode    = result.ResultCode;
                resultmessage = result.Message;
                resultval     = result.IsSuccess;
                _logs.Add(userInfo.SessId, string.Format("Makale ekleme işlemi tamamlanmıştır.Sonuç={0}", (resultval ? "Başarılı" : "Hatalı")), "AddArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "AddArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            return(new Result(resultval, resultmessage, resultcode));
        }
Example #17
0
        public IObjResult <List <Articles> > GetListByWriterId([FromBody] int writerid)
        {
            AutUserInfo     userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string          resultmessage = StaticValues.ErrorMessage;
            int             resultcode    = StaticValues.ErrorCode;
            bool            resultval     = false;
            List <Articles> resultobj     = null;

            _memcache.TryGetValue <List <Articles> >("ArticlesByWriters" + writerid, out resultobj);
            try
            {
                if (resultobj == null)
                {
                    var result = _article.GetListByWriter(writerid, userInfo);
                    resultcode    = result.ResultCode;
                    resultmessage = result.Message;
                    resultval     = result.IsSuccess;
                    resultobj     = result.Object;
                    if (result.IsSuccess)
                    {
                        _memcache.Set <List <Articles> >("ArticlesByWriters" + writerid, resultobj);
                    }
                }
                else
                {
                    resultcode    = StaticValues.SuccessCode;
                    resultmessage = StaticValues.SuccessMessage;
                    resultval     = true;
                }
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "GetListByWriterId", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            return(new ObjResult <List <Articles> >(resultval, resultmessage, resultcode, resultobj));
        }