コード例 #1
0
 public string GenerateToken(UserModel user)
 {
     try
     {
         var tokenHandler    = new JwtSecurityTokenHandler();
         var key             = Encoding.ASCII.GetBytes(_appSetting.JwtKey);
         var tokenDescriptor = new SecurityTokenDescriptor
         {
             Subject = new ClaimsIdentity(new Claim[]
             {
                 new Claim("UserID", user.UserID.ToString()),
                 new Claim("UserName", user.Username.ToString())
             }),
             Expires            = DateTime.Now.AddHours(_appSetting.TokenExpire),
             SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
         };
         var token = tokenHandler.CreateToken(tokenDescriptor);
         return(tokenHandler.WriteToken(token));
     }
     catch (Exception ex)
     {
         NLogLogger.Exception(ex);
         return(null);
     }
 }
コード例 #2
0
 public List <ProgramModel> SP_Event_GetList_Web(int EventID, string EventName, int IsSetted, int Page, int PageSize, out int TotalRow)
 {
     TotalRow = 0;
     try
     {
         var pars = new SqlParameter[6];
         pars[0] = new SqlParameter("@EventID", EventID);
         pars[1] = new SqlParameter("@EventName", EventName);
         if (IsSetted == -1)
         {
             pars[2] = new SqlParameter("@IsSetted", DBNull.Value);
         }
         else if (IsSetted == 1)
         {
             pars[2] = new SqlParameter("@IsSetted", true);
         }
         pars[3] = new SqlParameter("@Page", Page);
         pars[4] = new SqlParameter("@PageSize", PageSize);
         pars[5] = new SqlParameter("@TotalRow", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         var list = db.GetListSP <ProgramModel>("SP_Event_GetList_Web", pars);
         if (list != null || list.Count >= 0)
         {
             TotalRow = Convert.ToInt32(pars[5].Value);
         }
         return(list);
     }
     catch (Exception ex)
     {
         NLogLogger.Exception(ex);
         return(new List <ProgramModel>());
     }
 }
コード例 #3
0
        public static async Task <T> GetAsync <T>(string uri)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    NLogLogger.Info(string.Format("Input {0}: ", uri));
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
                    // httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Partner-Key", partnerCode);

                    var response = await httpClient.GetAsync(uri).ConfigureAwait(false);

                    var content = await response.Content.ReadAsStringAsync();

                    if (string.IsNullOrWhiteSpace(content))
                    {
                        throw new Exception();
                    }

                    NLogLogger.Info("Output: " + content);
                    return(JsonConvert.DeserializeObject <T>(content));
                }
            }
            catch (TaskCanceledException ex)
            {
                NLogLogger.Exception(ex);
                return(default(T));
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return(default(T));
            }
        }
コード例 #4
0
        public AdminModel Login(string UserName, string Password, ref int ResponseStatus)
        {
            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_ResponseStatus", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    },
                    new SqlParameter("@_UserName", UserName),
                    new SqlParameter("@_Password", Password),
                };

                var data = db.GetInstanceSP <AdminModel>("SP_Users_CheckLogin", pars);
                ResponseStatus = Convert.ToInt32(pars[0].Value);
                NLogLogger.Info(string.Format("Login Out: {0} {1} ", ResponseStatus, data));
                return(data);
            }
            catch (Exception e)
            {
                NLogLogger.Exception(e);
                ResponseStatus = -99;
                return(new AdminModel());
            }
        }
コード例 #5
0
        public List <ArticleModel> SP_Article_GetTopView_Web(int TopRow, int MenuID, string UrlRedirect, int Page, int PageSize, out int TotalRow)
        {
            TotalRow = 0;
            try
            {
                var pars = new SqlParameter[6];
                pars[0] = new SqlParameter("@TopRow", TopRow);
                pars[1] = new SqlParameter("@MenuID", MenuID);
                pars[2] = new SqlParameter("@Page", Page);
                pars[3] = new SqlParameter("@PageSize", PageSize);
                pars[4] = new SqlParameter("@TotalRow", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Output
                };
                pars[5] = new SqlParameter("@UrlRedirect", UrlRedirect);
                var list = db.GetListSP <ArticleModel>("SP_Article_GetTopView_Web", pars);

                if (list != null || list.Count >= 0)
                {
                    TotalRow = Convert.ToInt32(pars[4].Value);
                }
                return(list);
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return(new List <ArticleModel>());
            }
        }
コード例 #6
0
        public int SP_GifCodeData_Transaction(int GiftCodeID, string GiftCode, long Value, int SourceID, int Type, DateTime EndTime, string ClientIP)
        {
            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_ResponseStatus", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    },
                    new SqlParameter("@_GifCodeID", GiftCodeID),
                    new SqlParameter("@_GifCode", GiftCode),
                    new SqlParameter("@_Value", Value),
                    new SqlParameter("@_SourceID", SourceID),
                    new SqlParameter("@_Type", Type),
                    new SqlParameter("@_EndDate", EndTime),
                    new SqlParameter("@_MerchantID", _appSetting.MerchantIdGiftCodeInsert),
                    new SqlParameter("@_MerchantKey", _appSetting.MerchantKeyGiftCodeInsert.ToString()),
                    new SqlParameter("@_ClientIP", ClientIP),
                };

                db.ExecuteNonQuerySP("SP_GifCodeData_Transaction", pars);

                NLogLogger.Info(string.Format("SP_GifCodeData_Transaction Output _ResponseStatus: {0}", pars[0].Value));

                return(int.Parse(pars[0].Value.ToString()));
            }
            catch (Exception e)
            {
                NLogLogger.Exception(e);
                return(-99);
            }
        }
コード例 #7
0
        public List <GiftCodeData> SP_CMS_EventGiftcodeDetail(int GiftcodeID, int IsUsed, int Page, int Size, ref long TotalRow)
        {
            var lst = new List <GiftCodeData>();

            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_TotalRow", SqlDbType.BigInt)
                    {
                        Direction = ParameterDirection.Output
                    },
                    new SqlParameter("@_GiftcodeID", GiftcodeID),
                    new SqlParameter("@_IsUsed", IsUsed),
                    new SqlParameter("@_Page", Page),
                    new SqlParameter("@_Size", Size),
                };
                lst      = db.GetListSP <GiftCodeData>("SP_CMS_EventGiftcodeDetail", pars);
                TotalRow = Convert.ToInt64(pars[0].Value.ToString());
            }
            catch (Exception e)
            {
                NLogLogger.Exception(e);
            }
            return(lst);
        }
コード例 #8
0
 public List <ArticleImage> SP_ArticleImage_GetList(int TopRow, int ImageID, int ArticleID, int Status, int Page, int PageSize, out int TotalRow)
 {
     try
     {
         var pars = new SqlParameter[7];
         pars[0] = new SqlParameter("@TopRow", TopRow);
         pars[1] = new SqlParameter("@ImageID", ImageID);
         pars[2] = new SqlParameter("@ArticleID", ArticleID);
         pars[3] = new SqlParameter("@Status", Status);
         pars[4] = new SqlParameter("@Page", Page);
         pars[5] = new SqlParameter("@PageSize", PageSize);
         pars[6] = new SqlParameter("@TotalRow", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         var list = db.GetListSP <ArticleImage>("SP_ArticleImage_GetList", pars);
         TotalRow = Convert.ToInt32(pars[6].Value);
         return(list);
     }
     catch (Exception ex)
     {
         NLogLogger.Exception(ex);
         TotalRow = 0;
         return(new List <ArticleImage>());
     }
 }
コード例 #9
0
        public int SP_Article_INUP_CMS(ArticleModel article)
        {
            try
            {
                var pars = new SqlParameter[16];
                pars[0]  = new SqlParameter("@ArticleID", article.ArticleID);
                pars[1]  = new SqlParameter("@Title", article.Title);
                pars[2]  = new SqlParameter("@MenuID", article.MenuID);
                pars[3]  = new SqlParameter("@Description", article.Description);
                pars[4]  = new SqlParameter("@Detail", article.Detail);
                pars[5]  = new SqlParameter("@Image", article.Image);
                pars[6]  = new SqlParameter("@ImageDetail", article.ImageDetail);
                pars[7]  = new SqlParameter("@ImageHot", article.ImageHot);
                pars[8]  = new SqlParameter("@MetaData", article.MetaData);
                pars[9]  = new SqlParameter("@BottomDesc", article.BottomDesc);
                pars[10] = new SqlParameter("@Tags", article.Tags);
                pars[11] = new SqlParameter("@PublishDate", article.PublishDate);
                pars[12] = new SqlParameter("@isHot", article.isHot);
                pars[13] = new SqlParameter("@Author", article.Author);
                pars[14] = new SqlParameter("@CreateUser", article.CreateUser);
                pars[15] = new SqlParameter("@ResponseStatus", DbType.Int32)
                {
                    Direction = ParameterDirection.Output
                };

                db.ExecuteNonQuerySP("SP_Article_INUP_CMS", pars);
                return(Convert.ToInt32(pars[15].Value));
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return(-99);
            }
        }
コード例 #10
0
 public List <MenuModel> SP_Menu_GetList(string MenuIDs, Int16 GetChild, Int16 Status, out int TotalRow)
 {
     TotalRow = 0;
     try
     {
         var pars = new SqlParameter[4];
         pars[0] = new SqlParameter("@MenuIDs", MenuIDs);
         pars[1] = new SqlParameter("@GetChild", GetChild);
         pars[2] = new SqlParameter("@Status", Status);
         pars[3] = new SqlParameter("@TotalRow", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         var list = db.GetListSP <MenuModel>("SP_Menu_GetList", pars);
         if (list != null && list.Count >= 0)
         {
             TotalRow = Convert.ToInt32(pars[3].Value);
         }
         NLogLogger.Info(JsonConvert.SerializeObject(list));
         return(list);
     }
     catch (Exception ex)
     {
         NLogLogger.Exception(ex);
         return(new List <MenuModel>());
     }
 }
コード例 #11
0
        public int SP_GifCode_Event_Insert(string GiftCodeName, long GiftCodeValue, int EventID, int Quantity, int SourceID, string ClientIP, int NumberInput, ref long Balance, ref DateTime EndDate)
        {
            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_Balance", SqlDbType.BigInt)
                    {
                        Direction = ParameterDirection.Output
                    },
                    new SqlParameter("@_ResponseStatus", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    },
                    new SqlParameter("@_EndDate", SqlDbType.DateTime)
                    {
                        Direction = ParameterDirection.Output
                    },
                    new SqlParameter("@_GifCodeName", GiftCodeName),
                    new SqlParameter("@_GifCodeValue", GiftCodeValue),
                    new SqlParameter("@_EventID", EventID),
                    //new SqlParameter("@_EventName", DBNull.Value),
                    new SqlParameter("@_Quantity", Convert.ToInt64(Quantity)),
                    new SqlParameter("@_Staff", _accountJwt.AccountName),
                    new SqlParameter("@_SourceID", SourceID),
                    new SqlParameter("@_MerchantID", _appSetting.MerchantIdGiftCodeInsert),
                    new SqlParameter("@_MerchantKey", _appSetting.MerchantKeyGiftCodeInsert.ToString()),
                    new SqlParameter("@_ClientIP", ClientIP),
                    new SqlParameter("@_NumberInput", NumberInput),
                    //new SqlParameter("@_Note", DBNull.Value),
                };

                db.ExecuteNonQuerySP("SP_GifCode_Event_Insert", pars);

                NLogLogger.Info(string.Format("SP_GifCode_Event_Insert Output _Balance: {0} | _ResponseStatus: {1} | _EndDate :  {2}", pars[0].Value, pars[1].Value, pars[2].Value));

                Balance = Convert.ToInt64(pars[0].Value.ToString());
                EndDate = DateTime.Parse(pars[2].Value.ToString());

                return(int.Parse(pars[1].Value.ToString()));
            }
            catch (Exception e)
            {
                NLogLogger.Exception(e);
                Balance = 0;
                EndDate = new DateTime();
                return(-99);
            }
        }
コード例 #12
0
        public int SP_Advert_Delete(int Id)
        {
            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_ID", Id),
                };

                db.ExecuteNonQuerySP("SP_Advert_Delete", pars);
                return 1;
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return -99;
            }
        }
コード例 #13
0
        public List<AdvertPosModel> SP_AdvertPosition_Get()
        {
            try
            {
                var pars = new SqlParameter[] {
                };

                var list = db.GetListSP<AdvertPosModel>("SP_AdvertPosition_Get", pars);
                NLogLogger.Info(JsonConvert.SerializeObject(list));

                return list;
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return new List<AdvertPosModel>();
            }
        }
コード例 #14
0
 public List <ArticleModel> SP_Article_GetList_Web(int TopRow, int ArticleID, string Title, int MenuID, string UrlRedirect, string Tags, int isHot, int Page, int PageSize, out int TotalRow)
 {
     TotalRow = 0;
     try
     {
         var pars = new SqlParameter[10];
         pars[0] = new SqlParameter("@TopRow", TopRow);
         pars[1] = new SqlParameter("@ArticleID", ArticleID);
         pars[2] = new SqlParameter("@Title", Title);
         pars[3] = new SqlParameter("@MenuID", MenuID);
         pars[4] = new SqlParameter("@UrlRedirect", UrlRedirect);
         pars[5] = new SqlParameter("@Tags", Tags);
         if (isHot == -1)
         {
             pars[6] = new SqlParameter("@isHot", DBNull.Value);
         }
         else if (isHot == 1)
         {
             pars[6] = new SqlParameter("@isHot", true);
         }
         else if (isHot == 0)
         {
             pars[6] = new SqlParameter("@isHot", false);
         }
         pars[7] = new SqlParameter("@Page", Page);
         pars[8] = new SqlParameter("@PageSize", PageSize);
         pars[9] = new SqlParameter("@TotalRow", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         var list = db.GetListSP <ArticleModel>("SP_Article_GetList_Web", pars);
         if (list != null || list.Count >= 0)
         {
             TotalRow = Convert.ToInt32(pars[9].Value);
         }
         NLogLogger.Info(JsonConvert.SerializeObject(list));
         return(list);
     }
     catch (Exception ex)
     {
         NLogLogger.Exception(ex);
         return(new List <ArticleModel>());
     }
 }
コード例 #15
0
        //Lấy ds tài khoản hoặc thông tin chi tiết
        public List <AdminModel> SP_User_GetListAndInfo(int Id, string TextSearch, int Status)
        {
            var lst = new List <AdminModel>();

            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_Id", Id),
                    new SqlParameter("@_TextSearch", TextSearch),
                    new SqlParameter("@_Status", Status),
                };

                lst = db.GetListSP <AdminModel>("SP_User_GetListAndInfo", pars);
            }
            catch (Exception e)
            {
                NLogLogger.Exception(e);
            }
            return(lst);
        }
コード例 #16
0
 public List <ArticleModel> SP_Article_GetList_CMS(int ArticleID, string Title, int MenuID, string Tags, int isHot, int Status, string FromDate, string ToDate, int Page, int PageSize, out int TotalRow)
 {
     try
     {
         var pars = new SqlParameter[11];
         pars[0] = new SqlParameter("@ArticleID", ArticleID);
         pars[1] = new SqlParameter("@Title", Title);
         pars[2] = new SqlParameter("@MenuID", MenuID);
         pars[3] = new SqlParameter("@Tags", Tags);
         if (isHot == -1)
         {
             pars[4] = new SqlParameter("@isHot", DBNull.Value);
         }
         else if (isHot == 0)
         {
             pars[4] = new SqlParameter("@isHot", false);
         }
         else
         {
             pars[4] = new SqlParameter("@isHot", true);
         }
         pars[5]  = new SqlParameter("@Status", Status);
         pars[6]  = new SqlParameter("@FromDate", FromDate);
         pars[7]  = new SqlParameter("@ToDate", ToDate);
         pars[8]  = new SqlParameter("@Page", Page);
         pars[9]  = new SqlParameter("@PageSize", PageSize);
         pars[10] = new SqlParameter("@TotalRow", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         var list = db.GetListSP <ArticleModel>("SP_Article_GetList_CMS", pars);
         TotalRow = Convert.ToInt32(pars[10].Value);
         return(list);
     }
     catch (Exception ex)
     {
         NLogLogger.Exception(ex);
         TotalRow = 0;
         return(new List <ArticleModel>());
     }
 }
コード例 #17
0
        public List<AdvertModel> SP_Advert_GetList(int PostID, int Type, int Status)
        {
            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_PostID", PostID),
                    new SqlParameter("@_Type", Type),
                    new SqlParameter("@_Status", Status)
                };

                var list = db.GetListSP<AdvertModel>("SP_Advert_GetList", pars);
                NLogLogger.Info(JsonConvert.SerializeObject(list));

                return list;
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return new List<AdvertModel>();
            }
        }
コード例 #18
0
        public List <GiftCodeModel> SP_GiftCode_GetList(string GiftcodeName, int GiftcodeValue, int Status, string FromDate, string ToDate)
        {
            var lst = new List <GiftCodeModel>();

            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_GiftCodeName", GiftcodeName),
                    new SqlParameter("@_GiftCodeValue", GiftcodeValue),
                    new SqlParameter("@_Status", Status),
                    new SqlParameter("@_FromDate", FromDate),
                    new SqlParameter("@_ToDate", ToDate),
                };

                lst = db.GetListSP <GiftCodeModel>("SP_GiftCode_GetList", pars);
            }
            catch (Exception e)
            {
                NLogLogger.Exception(e);
            }
            return(lst);
        }
コード例 #19
0
        public int SP_Article_UpdateStatus_CMS(int ArticleID, int Status, string CreateUser)
        {
            try
            {
                var pars = new SqlParameter[4];
                pars[0] = new SqlParameter("@ArticleID", ArticleID);
                pars[1] = new SqlParameter("@Status", Status);
                pars[2] = new SqlParameter("@CreateUser", CreateUser);
                pars[3] = new SqlParameter("@ResponseStatus", DbType.Int32)
                {
                    Direction = ParameterDirection.Output
                };

                db.ExecuteNonQuerySP("SP_Article_UpdateStatus_CMS", pars);
                return(Convert.ToInt32(pars[3].Value));
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return(-99);
            }
        }
コード例 #20
0
        public List <EventGiftCode> SP_CMS_Event_GetList(string EventName, int EventValue, string Staff, string Fromdate, string Todate, int TypeSelect = 0)
        {
            var lst = new List <EventGiftCode>();

            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_TypeSelect", TypeSelect),
                    new SqlParameter("@_EventName", EventName),
                    new SqlParameter("@_EventValue", EventValue),
                    new SqlParameter("@_Staff", Staff),
                    new SqlParameter("@_Fromdate", Fromdate),
                    new SqlParameter("@_Todate", Todate)
                };
                lst = db.GetListSP <EventGiftCode>("SP_CMS_Event_GetList", pars);
            }
            catch (Exception e)
            {
                NLogLogger.Exception(e);
            }
            return(lst);
        }
コード例 #21
0
        public int SP_Advert_Insert(AdvertModel data)
        {
            try
            {
                var pars = new SqlParameter[] {
                    new SqlParameter("@_Id", data.Id),
                    new SqlParameter("@_Name", data.Name),
                    new SqlParameter("@_Type", data.Type),
                    new SqlParameter("@_Position", data.Position),
                    new SqlParameter("@_Image", data.Image),
                    new SqlParameter("@_Link", data.Link),
                    new SqlParameter("@_ScriptData", data.ScriptData)
                };
                //pars[15] = new SqlParameter("@ResponseStatus", DbType.Int32) { Direction = ParameterDirection.Output };

                db.ExecuteNonQuerySP("SP_Advert_Insert", pars);
                return 1;
            }
            catch (Exception ex)
            {
                NLogLogger.Exception(ex);
                return -99;
            }
        }