Ejemplo n.º 1
0
        // POST: odata/AdminMembers
        public IHttpActionResult Post(AdminMembers adminMembers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AdminMembers.Add(adminMembers);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (AdminMembersExists(adminMembers.AdminMemberID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "AdminMembers-POST";
            logMsg.memberID = JsonConvert.SerializeObject(adminMembers);
            Logging.RunLog(logMsg);

            return(Created(adminMembers));
        }
Ejemplo n.º 2
0
        /// Set redis rank by member
        public MemberRankNumber POST(InputParams p)
        {
            MemberRankNumber result = new MemberRankNumber();

            // Get the sid or memberID of the current user.
            var claimsPrincipal = this.User as ClaimsPrincipal;

            p.sid = CBAuth.getMemberID(p.sid, claimsPrincipal);

            /// logging purpose
            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(p.sid);


            try
            {
                /// set redis point and return
                CBRedis.SetSortedSetRank(p.sid, p.point);
                result.rank = CBRedis.GetSortedSetRank(p.sid);
                return(result);
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = p.sid;       // requested value. Not redis data value.
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBRankController-SetMemberPoint";
                logMessage.Message   = jsonParam;
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }
Ejemplo n.º 3
0
        // DELETE: odata/Members(5)
        public IHttpActionResult Delete([FromODataUri] string key)
        {
            Members members = db.Members.Find(key);

            if (members == null)
            {
                return(NotFound());
            }

            db.Members.Remove(members);
            db.SaveChanges();

            // Log Message
            logMsg = new Logging.CBLoggers
            {
                memberID = CBAuth.getMemberID(this.User as ClaimsPrincipal),
                Level    = "INFO",
                Logger   = "Members-DELETE",
                Message  = key
            };

            Logging.RunLog(logMsg);

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public SortedSetEntry[] GET(string sid, long startRank, long endRank)   /// @todo not a good idea getting sid from usermode
        {
            // Get the sid or memberID of the current user.
            var claimsPrincipal = this.User as ClaimsPrincipal;

            sid = CBAuth.getMemberID(sid, claimsPrincipal);

            /// logging purpose
            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(sid);

            try
            {
                /// fetch redis list by rank range
                SortedSetEntry[] se = CBRedis.GetSortedSetRankByRange(startRank, endRank);
                return(se);
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = sid;       // server autenticated sid
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBRankController-RankerListByRange";
                logMessage.Message   = jsonParam;
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }
Ejemplo n.º 5
0
        public MemberRankNumber Get(string sid)
        {
            MemberRankNumber result = new MemberRankNumber();

            // Get the sid or memberID of the current user.
            var claimsPrincipal = this.User as ClaimsPrincipal;

            sid = CBAuth.getMemberID(sid, claimsPrincipal);

            /// logging purpose
            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(sid);

            try
            {
                /// fetch redis value by member sid
                result.rank = CBRedis.GetSortedSetRank(sid);

                return(result);
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = sid;       // authenricated server sid
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBRankController-MemberRankNumber";
                logMessage.Message   = jsonParam;
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }
Ejemplo n.º 6
0
        public SortedSetEntry[] GET(string sid, int countnum)
        {
            // Get the sid or memberID of the current user.
            var claimsPrincipal = this.User as ClaimsPrincipal;

            sid = CBAuth.getMemberID(sid, claimsPrincipal);

            /// logging purpose
            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(sid);

            try
            {
                /// fetch redis list by top countnum rankers
                SortedSetEntry[] sse = CBRedis.GetTopSortedSetRank(countnum);
                return(sse);
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = sid;       // server authenticated value
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBRankController-TopRankerList";
                logMessage.Message   = jsonParam;
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }
Ejemplo n.º 7
0
        // POST api/ping - return current authentication member SID
        public string Post()
        {
            string sid;
            // Get the sid or memberID of the current user.
            var claimsPrincipal = this.User as ClaimsPrincipal;

            sid = CBAuth.getMemberID("non-auth member", claimsPrincipal);

            return("Hello " + sid);
        }
Ejemplo n.º 8
0
        public SingleResult <AdminMembers> GetAdminMembers([FromODataUri] string key)
        {
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "AdminMembers-GETbyID";
            logMsg.memberID = this.Request.RequestUri.PathAndQuery.ToString();
            Logging.RunLog(logMsg);

            return(SingleResult.Create(db.AdminMembers.Where(adminMembers => adminMembers.AdminMemberID == key)));
        }
Ejemplo n.º 9
0
        public IQueryable <CloudBreadAdminLog> GetCloudBreadAdminLogs()
        {
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "CloudBreadAdminLogs-GET";
            logMsg.Message  = this.Request.RequestUri.PathAndQuery.ToString();
            Logging.RunLog(logMsg);

            return(db.CloudBreadAdminLog);
        }
Ejemplo n.º 10
0
        public SingleResult <MemberItems> GetMemberItems([FromODataUri] string key)
        {
            // Get the sid of the current user
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "MemberItems-GETbyID";
            logMsg.Message  = this.Request.RequestUri.PathAndQuery.ToString();
            Logging.RunLog(logMsg);

            return(SingleResult.Create(db.MemberItems.Where(memberItems => memberItems.MemberItemID == key)));
        }
Ejemplo n.º 11
0
        public IQueryable <Members> GetMembers()
        {
            // Get the sid of the current user
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "Members-get";
            logMsg.Message  = this.Request.RequestUri.PathAndQuery.ToString();
            Logging.RunLog(logMsg);

            return(db.Members);
        }
Ejemplo n.º 12
0
        public IQueryable <CloudBreadErrorLog> GetCloudBreadErrorLogs()
        {
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            // admin access log
            logMessage.memberID = sid;
            logMessage.Level    = "INFO";
            logMessage.Logger   = "CBErrorLogs-Get";
            logMessage.Message  = this.Request.RequestUri.PathAndQuery.ToString();
            Logging.RunLog(logMessage);

            return(db.CloudBreadErrorLog);
        }
Ejemplo n.º 13
0
        public SingleResult <Members> GetMembers([FromODataUri] string key)
        {
            logMsg = new Logging.CBLoggers
            {
                memberID = CBAuth.getMemberID(this.User as ClaimsPrincipal),
                Level    = "INFO",
                Logger   = "Members-GetbyID",
                Message  = this.Request.RequestUri.PathAndQuery.ToString()
            };
            Logging.RunLog(logMsg);

            return(SingleResult.Create(db.Members.Where(members => members.MemberID == key)));
        }
Ejemplo n.º 14
0
        public IQueryable <ItemLists> GetItemLists()
        {
            // Get the sid of the current user.
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            /// admin access log
            logMessage.memberID = sid;
            logMessage.Level    = "INFO";
            logMessage.Logger   = "ItemLists-Get";
            logMessage.Message  = this.Request.RequestUri.PathAndQuery.ToString();
            Logging.RunLog(logMessage);

            return(db.ItemLists);
        }
Ejemplo n.º 15
0
        public SingleResult <ItemLists> GetItemLists([FromODataUri] string key)
        {
            // Get the sid of the current user.
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            /// admin access log
            logMessage.memberID = sid;
            logMessage.Level    = "INFO";
            logMessage.Logger   = "ItemLists-GetbyID";
            logMessage.Message  = this.Request.RequestUri.PathAndQuery.ToString();
            Logging.RunLog(logMessage);

            return(SingleResult.Create(db.ItemLists.Where(itemLists => itemLists.ItemListID == key)));
        }
Ejemplo n.º 16
0
        // GET api/CBSocketAuth
        public Payload Get()
        {
            Payload payload = new Payload();

            /// Get the sid or memberID of the current user.
            string sid = CBAuth.getMemberID("debug", this.User as ClaimsPrincipal);  // only for log

            payload.sid = sid;

            /// logging purpose
            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(sid);

            try
            {
                /// return token object
                Token t = new Token();

                /// generate paylod
                payload.guid       = Guid.NewGuid().ToString();
                payload.genDateUTC = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");;

                /// token Serialize and encrypt
                t.token = JsonConvert.SerializeObject(payload);

                /// save to Rdis
                CBRedis.SetRedisKey(payload.guid, t.token, 30); // 30 min for socket suth TTL

                payload.sid        = "";
                payload.genDateUTC = "";
                /// @brief chagned for plain processing - token encrypt
                //t.token = Crypto.AES_encrypt(t.token, globalVal.CloudBreadSocketKeyText, globalVal.CloudBreadSocketKeyIV);

                return(payload);     //changed
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = sid;
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBSocketAuth";
                logMessage.Message   = "SocketAuth error";
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }
Ejemplo n.º 17
0
        // PUT: odata/Members(5)
        public IHttpActionResult Put([FromODataUri] string key, Delta <Members> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Members members = db.Members.Find(key);

            if (members == null)
            {
                return(NotFound());
            }

            patch.Put(members);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MembersExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            // Log Message
            logMsg = new Logging.CBLoggers
            {
                memberID = CBAuth.getMemberID(this.User as ClaimsPrincipal),
                Level    = "INFO",
                Logger   = "Members-PUT",
                Message  = JsonConvert.SerializeObject(patch)
            };

            Logging.RunLog(logMsg);

            return(Updated(members));
        }
Ejemplo n.º 18
0
        // PUT: odata/ItemLists(5)
        public IHttpActionResult Put([FromODataUri] string key, Delta <ItemLists> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ItemLists itemLists = db.ItemLists.Find(key);

            if (itemLists == null)
            {
                return(NotFound());
            }

            patch.Put(itemLists);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemListsExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            // Get the sid of the current user.
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            /// admin access log
            logMessage.memberID = sid;
            logMessage.Level    = "INFO";
            logMessage.Logger   = "ItemLists-PUT";
            logMessage.Message  = JsonConvert.SerializeObject(patch);
            Logging.RunLog(logMessage);

            return(Updated(itemLists));
        }
Ejemplo n.º 19
0
        public IHttpActionResult Patch([FromODataUri] string key, Delta <MemberItems> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            MemberItems memberItems = db.MemberItems.Find(key);

            if (memberItems == null)
            {
                return(NotFound());
            }

            patch.Patch(memberItems);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MemberItemsExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            // Get the sid of the current user
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "MemberItems-PATCH";
            logMsg.Message  = JsonConvert.SerializeObject(patch);
            Logging.RunLog(logMsg);

            return(Updated(memberItems));
        }
Ejemplo n.º 20
0
        // PUT: odata/AdminMembers(5)
        public IHttpActionResult Put([FromODataUri] string key, Delta <AdminMembers> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AdminMembers adminMembers = db.AdminMembers.Find(key);

            if (adminMembers == null)
            {
                return(NotFound());
            }

            patch.Put(adminMembers);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdminMembersExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "AdminMembers-PUT";
            logMsg.memberID = JsonConvert.SerializeObject(patch);
            Logging.RunLog(logMsg);

            return(Updated(adminMembers));
        }
Ejemplo n.º 21
0
        // DELETE: odata/AdminMembers(5)
        public IHttpActionResult Delete([FromODataUri] string key)
        {
            AdminMembers adminMembers = db.AdminMembers.Find(key);

            if (adminMembers == null)
            {
                return(NotFound());
            }

            db.AdminMembers.Remove(adminMembers);
            db.SaveChanges();

            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "AdminMembers-DELETE";
            logMsg.memberID = key;
            Logging.RunLog(logMsg);

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 22
0
            public Logging.CBLoggers build(ODataController controller, LevelType level, LoggerType type, string message = null)
            {
                string sid    = CBAuth.getMemberID(controller.User as ClaimsPrincipal);
                string logger = _controllerTag + "-" + type.ToString();

                if (message == null)
                {
                    switch (type)
                    {
                    case LoggerType.GET:
                    case LoggerType.GETbyIID:
                        message = controller.Request.RequestUri.PathAndQuery.ToString();
                        break;

                    default:
                        message = "No Message";
                        break;
                    }
                }

                return(CBLoggerBuilder.Build(sid, level, logger, message));
            }
Ejemplo n.º 23
0
        // POST: odata/Members
        public IHttpActionResult Post(Members members)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Members.Add(members);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (MembersExists(members.MemberID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            // Log Message
            logMsg = new Logging.CBLoggers
            {
                memberID = CBAuth.getMemberID(this.User as ClaimsPrincipal),
                Level    = "INFO",
                Logger   = "Members-POST",
                Message  = JsonConvert.SerializeObject(members)
            };

            Logging.RunLog(logMsg);

            return(Created(members));
        }
Ejemplo n.º 24
0
        // DELETE: odata/MemberItems(5)
        public IHttpActionResult Delete([FromODataUri] string key)
        {
            MemberItems memberItems = db.MemberItems.Find(key);

            if (memberItems == null)
            {
                return(NotFound());
            }

            db.MemberItems.Remove(memberItems);
            db.SaveChanges();

            // Get the sid of the current user
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "MemberItems-DELETE";
            logMsg.Message  = key;
            Logging.RunLog(logMsg);

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 25
0
        // POST: odata/ItemLists
        public IHttpActionResult Post(ItemLists itemLists)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ItemLists.Add(itemLists);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ItemListsExists(itemLists.ItemListID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            // Get the sid of the current user.
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            /// admin access log
            logMessage.memberID = sid;
            logMessage.Level    = "INFO";
            logMessage.Logger   = "ItemLists-POST";
            logMessage.Message  = JsonConvert.SerializeObject(itemLists);
            Logging.RunLog(logMessage);

            return(Created(itemLists));
        }
Ejemplo n.º 26
0
        // DELETE: odata/ItemLists(5)
        public IHttpActionResult Delete([FromODataUri] string key)
        {
            ItemLists itemLists = db.ItemLists.Find(key);

            if (itemLists == null)
            {
                return(NotFound());
            }

            db.ItemLists.Remove(itemLists);
            db.SaveChanges();

            // Get the sid of the current user.
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            /// admin access log
            logMessage.memberID = sid;
            logMessage.Level    = "INFO";
            logMessage.Logger   = "ItemLists-DELETE";
            logMessage.Message  = key;
            Logging.RunLog(logMessage);

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 27
0
        // POST: odata/Notices
        public IHttpActionResult Post(Notices notices)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Notices.Add(notices);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (NoticesExists(notices.NoticeID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            // Get the sid of the current user
            string sid = CBAuth.getMemberID(this.User as ClaimsPrincipal);

            logMsg.memberID = sid;
            logMsg.Level    = "INFO";
            logMsg.Logger   = "Notices-POST";
            logMsg.Message  = JsonConvert.SerializeObject(notices);
            Logging.RunLog(logMsg);

            return(Created(notices));
        }
Ejemplo n.º 28
0
        public HttpResponseMessage Post(SelItem1InputParams p)
        {
            // try decrypt data
            if (!string.IsNullOrEmpty(p.token) && globalVal.CloudBreadCryptSetting == "AES256")
            {
                try
                {
                    string decrypted = Crypto.AES_decrypt(p.token, globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
                    p = JsonConvert.DeserializeObject <SelItem1InputParams>(decrypted);
                }
                catch (Exception ex)
                {
                    ex = (Exception)Activator.CreateInstance(ex.GetType(), "Decrypt Error", ex);
                    throw ex;
                }
            }

            // Get the sid or memberID of the current user.
            string sid = CBAuth.getMemberID(p.MemberID, this.User as ClaimsPrincipal);

            p.MemberID = sid;

            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(p);

            List <SelItem1Model> result          = new List <SelItem1Model>();
            HttpResponseMessage  response        = new HttpResponseMessage();
            EncryptedData        encryptedResult = new EncryptedData();

            try
            {
                /// Database connection retry policy
                RetryPolicy retryPolicy = new RetryPolicy <SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds));
                using (SqlConnection connection = new SqlConnection(globalVal.DBConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("uspSelItem1", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add("@ItemListID", SqlDbType.NVarChar, -1).Value = p.ItemListID;
                        connection.OpenWithRetry(retryPolicy);

                        using (SqlDataReader dreader = command.ExecuteReaderWithRetry(retryPolicy))
                        {
                            while (dreader.Read())
                            {
                                SelItem1Model workItem = new SelItem1Model()
                                {
                                    ItemListID      = dreader[0].ToString(),
                                    ItemName        = dreader[1].ToString(),
                                    ItemDescription = dreader[2].ToString(),
                                    ItemPrice       = dreader[3].ToString(),
                                    ItemSellPrice   = dreader[4].ToString(),
                                    ItemCategory1   = dreader[5].ToString(),
                                    ItemCategory2   = dreader[6].ToString(),
                                    ItemCategory3   = dreader[7].ToString(),
                                    sCol1           = dreader[8].ToString(),
                                    sCol2           = dreader[9].ToString(),
                                    sCol3           = dreader[10].ToString(),
                                    sCol4           = dreader[11].ToString(),
                                    sCol5           = dreader[12].ToString(),
                                    sCol6           = dreader[13].ToString(),
                                    sCol7           = dreader[14].ToString(),
                                    sCol8           = dreader[15].ToString(),
                                    sCol9           = dreader[16].ToString(),
                                    sCol10          = dreader[17].ToString(),
                                };
                                result.Add(workItem);
                            }
                            dreader.Close();
                        }
                        connection.Close();
                    }

                    /// Encrypt the result response
                    if (globalVal.CloudBreadCryptSetting == "AES256")
                    {
                        try
                        {
                            encryptedResult.token = Crypto.AES_encrypt(JsonConvert.SerializeObject(result), globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
                            response = Request.CreateResponse(HttpStatusCode.OK, encryptedResult);
                            return(response);
                        }
                        catch (Exception ex)
                        {
                            ex = (Exception)Activator.CreateInstance(ex.GetType(), "Encrypt Error", ex);
                            throw ex;
                        }
                    }

                    response = Request.CreateResponse(HttpStatusCode.OK, result);
                    return(response);
                }
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = p.MemberID;
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBSelItem1Controller";
                logMessage.Message   = jsonParam;
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }
Ejemplo n.º 29
0
        public HttpResponseMessage Post(UdtGameEventMemberToItemInputParams p)
        {
            // try decrypt data
            if (!string.IsNullOrEmpty(p.token) && globalVal.CloudBreadCryptSetting == "AES256")
            {
                try
                {
                    string decrypted = Crypto.AES_decrypt(p.token, globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
                    p = JsonConvert.DeserializeObject <UdtGameEventMemberToItemInputParams>(decrypted);
                }
                catch (Exception ex)
                {
                    ex = (Exception)Activator.CreateInstance(ex.GetType(), "Decrypt Error", ex);
                    throw ex;
                }
            }

            // Get the sid or memberID of the current user.
            string sid = CBAuth.getMemberID(p.MemberID_MemberItems, this.User as ClaimsPrincipal);

            p.MemberID_MemberItems     = sid;
            p.MemberID_GameEventMember = sid;

            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(p);

            HttpResponseMessage response        = new HttpResponseMessage();
            EncryptedData       encryptedResult = new EncryptedData();
            RowcountResult      rowcountResult  = new RowcountResult();

            try
            {
                // start task log
                //logMessage.memberID = p.MemberID_MemberItems;
                //logMessage.Level = "INFO";
                //logMessage.Logger = "CBUdtGameEventMemberToItemController";
                //logMessage.Message = jsonParam;
                //Logging.RunLog(logMessage);

                /// Database connection retry policy
                RetryPolicy retryPolicy = new RetryPolicy <SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds));
                using (SqlConnection connection = new SqlConnection(globalVal.DBConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("uspUdtGameEventMemberToItem", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add("@InsertORUpdate ", SqlDbType.NVarChar, -1).Value           = p.InsertORUpdate.ToUpper();
                        command.Parameters.Add("@MemberItemID_MemberItems ", SqlDbType.NVarChar, -1).Value = p.MemberItemID_MemberItems;
                        command.Parameters.Add("@MemberID_MemberItems", SqlDbType.NVarChar, -1).Value      = p.MemberID_MemberItems;
                        command.Parameters.Add("@ItemListID_MemberItems", SqlDbType.NVarChar, -1).Value    = p.ItemListID_MemberItems;
                        command.Parameters.Add("@ItemCount_MemberItems", SqlDbType.NVarChar, -1).Value     = p.ItemCount_MemberItems;
                        command.Parameters.Add("@ItemStatus_MemberItems", SqlDbType.NVarChar, -1).Value    = p.ItemStatus_MemberItems;
                        command.Parameters.Add("@sCol1_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol1_MemberItems;
                        command.Parameters.Add("@sCol2_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol2_MemberItems;
                        command.Parameters.Add("@sCol3_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol3_MemberItems;
                        command.Parameters.Add("@sCol4_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol4_MemberItems;
                        command.Parameters.Add("@sCol5_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol5_MemberItems;
                        command.Parameters.Add("@sCol6_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol6_MemberItems;
                        command.Parameters.Add("@sCol7_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol7_MemberItems;
                        command.Parameters.Add("@sCol8_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol8_MemberItems;
                        command.Parameters.Add("@sCol9_MemberItems", SqlDbType.NVarChar, -1).Value         = p.sCol9_MemberItems;
                        command.Parameters.Add("@sCol10_MemberItems", SqlDbType.NVarChar, -1).Value        = p.sCol10_MemberItems;
                        command.Parameters.Add("@eventID_GameEventMember", SqlDbType.NVarChar, -1).Value   = p.eventID_GameEventMember;
                        command.Parameters.Add("@MemberID_GameEventMember ", SqlDbType.NVarChar, -1).Value = p.MemberID_GameEventMember;
                        command.Parameters.Add("@sCol1_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol1_GameEventMember;
                        command.Parameters.Add("@sCol2_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol2_GameEventMember;
                        command.Parameters.Add("@sCol3_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol3_GameEventMember;
                        command.Parameters.Add("@sCol4_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol4_GameEventMember;
                        command.Parameters.Add("@sCol5_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol5_GameEventMember;
                        command.Parameters.Add("@sCol6_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol6_GameEventMember;
                        command.Parameters.Add("@sCol7_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol7_GameEventMember;
                        command.Parameters.Add("@sCol8_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol8_GameEventMember;
                        command.Parameters.Add("@sCol9_GameEventMember ", SqlDbType.NVarChar, -1).Value    = p.sCol9_GameEventMember;
                        command.Parameters.Add("@sCol10_GameEventMember ", SqlDbType.NVarChar, -1).Value   = p.sCol10_GameEventMember;

                        connection.OpenWithRetry(retryPolicy);
                        using (SqlDataReader dreader = command.ExecuteReaderWithRetry(retryPolicy))
                        {
                            while (dreader.Read())
                            {
                                rowcountResult.result = dreader[0].ToString();
                            }
                            dreader.Close();
                        }
                        connection.Close();

                        // end task log
                        logMessage.memberID = p.MemberID_MemberItems;
                        logMessage.Level    = "INFO";
                        logMessage.Logger   = "CBUdtGameEventMemberToItemController";
                        logMessage.Message  = jsonParam;
                        Logging.RunLog(logMessage);

                        /// Encrypt the result response
                        if (globalVal.CloudBreadCryptSetting == "AES256")
                        {
                            try
                            {
                                encryptedResult.token = Crypto.AES_encrypt(JsonConvert.SerializeObject(rowcountResult), globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
                                response = Request.CreateResponse(HttpStatusCode.OK, encryptedResult);
                                return(response);
                            }
                            catch (Exception ex)
                            {
                                ex = (Exception)Activator.CreateInstance(ex.GetType(), "Encrypt Error", ex);
                                throw ex;
                            }
                        }

                        response = Request.CreateResponse(HttpStatusCode.OK, rowcountResult);
                        return(response);
                    }
                }
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = p.MemberID_MemberItems;
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBUdtGameEventMemberToItemController";
                logMessage.Message   = jsonParam;
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }
Ejemplo n.º 30
0
        public HttpResponseMessage Post(ComUdtMemberItemPurchaseInputParams p)
        {
            // try decrypt data
            if (!string.IsNullOrEmpty(p.token) && globalVal.CloudBreadCryptSetting == "AES256")
            {
                try
                {
                    string decrypted = Crypto.AES_decrypt(p.token, globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
                    p = JsonConvert.DeserializeObject <ComUdtMemberItemPurchaseInputParams>(decrypted);
                }
                catch (Exception ex)
                {
                    ex = (Exception)Activator.CreateInstance(ex.GetType(), "Decrypt Error", ex);
                    throw ex;
                }
            }

            // Get the sid or memberID of the current user.
            string sid = CBAuth.getMemberID(p.MemberID, this.User as ClaimsPrincipal);

            p.MemberID = sid;

            Logging.CBLoggers logMessage = new Logging.CBLoggers();
            string            jsonParam  = JsonConvert.SerializeObject(p);

            HttpResponseMessage response        = new HttpResponseMessage();
            EncryptedData       encryptedResult = new EncryptedData();
            RowcountResult      rowcountResult  = new RowcountResult();

            try
            {
                // task start log
                //logMessage.memberID = p.MemberID;
                //logMessage.Level = "INFO";
                //logMessage.Logger = "CBComUdtMemberItemPurchaseController";
                //logMessage.Message = jsonParam;
                //Logging.RunLog(logMessage);

                /// Database connection retry policy
                RetryPolicy retryPolicy = new RetryPolicy <SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds));
                using (SqlConnection connection = new SqlConnection(globalVal.DBConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("uspComUdtMemberItemPurchase", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.Add("@MemberItemPurchaseID", SqlDbType.NVarChar, -1).Value = p.MemberItemPurchaseID;
                        command.Parameters.Add("@MemberID", SqlDbType.NVarChar, -1).Value             = p.MemberID;
                        command.Parameters.Add("@ItemListID", SqlDbType.NVarChar, -1).Value           = p.ItemListID;
                        command.Parameters.Add("@PurchaseQuantity", SqlDbType.NVarChar, -1).Value     = p.PurchaseQuantity;
                        command.Parameters.Add("@PurchasePrice", SqlDbType.NVarChar, -1).Value        = p.PurchasePrice;
                        command.Parameters.Add("@PGinfo1", SqlDbType.NVarChar, -1).Value                        = p.PGinfo1;
                        command.Parameters.Add("@PGinfo2", SqlDbType.NVarChar, -1).Value                        = p.PGinfo2;
                        command.Parameters.Add("@PGinfo3", SqlDbType.NVarChar, -1).Value                        = p.PGinfo3;
                        command.Parameters.Add("@PGinfo4", SqlDbType.NVarChar, -1).Value                        = p.PGinfo4;
                        command.Parameters.Add("@PGinfo5", SqlDbType.NVarChar, -1).Value                        = p.PGinfo5;
                        command.Parameters.Add("@PurchaseDeviceID", SqlDbType.NVarChar, -1).Value               = p.PurchaseDeviceID;
                        command.Parameters.Add("@PurchaseDeviceIPAddress", SqlDbType.NVarChar, -1).Value        = p.PurchaseDeviceIPAddress;
                        command.Parameters.Add("@PurchaseDeviceMACAddress", SqlDbType.NVarChar, -1).Value       = p.PurchaseDeviceMACAddress;
                        command.Parameters.Add("@PurchaseDT", SqlDbType.NVarChar, -1).Value                     = p.PurchaseDT;
                        command.Parameters.Add("@PurchaseCancelYN", SqlDbType.NVarChar, -1).Value               = p.PurchaseCancelYN;
                        command.Parameters.Add("@PurchaseCancelDT", SqlDbType.NVarChar, -1).Value               = p.PurchaseCancelDT;
                        command.Parameters.Add("@PurchaseCancelingStatus", SqlDbType.NVarChar, -1).Value        = p.PurchaseCancelingStatus;
                        command.Parameters.Add("@PurchaseCancelReturnedAmount", SqlDbType.NVarChar, -1).Value   = p.PurchaseCancelReturnedAmount;
                        command.Parameters.Add("@PurchaseCancelDeviceID", SqlDbType.NVarChar, -1).Value         = p.PurchaseCancelDeviceID;
                        command.Parameters.Add("@PurchaseCancelDeviceIPAddress", SqlDbType.NVarChar, -1).Value  = p.PurchaseCancelDeviceIPAddress;
                        command.Parameters.Add("@PurchaseCancelDeviceMACAddress", SqlDbType.NVarChar, -1).Value = p.PurchaseCancelDeviceMACAddress;
                        command.Parameters.Add("@sCol1", SqlDbType.NVarChar, -1).Value  = p.sCol1;
                        command.Parameters.Add("@sCol2", SqlDbType.NVarChar, -1).Value  = p.sCol2;
                        command.Parameters.Add("@sCol3", SqlDbType.NVarChar, -1).Value  = p.sCol3;
                        command.Parameters.Add("@sCol4", SqlDbType.NVarChar, -1).Value  = p.sCol4;
                        command.Parameters.Add("@sCol5", SqlDbType.NVarChar, -1).Value  = p.sCol5;
                        command.Parameters.Add("@sCol6", SqlDbType.NVarChar, -1).Value  = p.sCol6;
                        command.Parameters.Add("@sCol7", SqlDbType.NVarChar, -1).Value  = p.sCol7;
                        command.Parameters.Add("@sCol8", SqlDbType.NVarChar, -1).Value  = p.sCol8;
                        command.Parameters.Add("@sCol9", SqlDbType.NVarChar, -1).Value  = p.sCol9;
                        command.Parameters.Add("@sCol10", SqlDbType.NVarChar, -1).Value = p.sCol10;

                        connection.OpenWithRetry(retryPolicy);
                        using (SqlDataReader dreader = command.ExecuteReaderWithRetry(retryPolicy))
                        {
                            while (dreader.Read())
                            {
                                rowcountResult.result = dreader[0].ToString();
                            }
                            dreader.Close();
                        }
                        connection.Close();

                        // task end log
                        logMessage.memberID = p.MemberID;
                        logMessage.Level    = "INFO";
                        logMessage.Logger   = "CBComUdtMemberItemPurchaseController";
                        logMessage.Message  = jsonParam;
                        Logging.RunLog(logMessage);

                        /// Encrypt the result response
                        if (globalVal.CloudBreadCryptSetting == "AES256")
                        {
                            try
                            {
                                encryptedResult.token = Crypto.AES_encrypt(JsonConvert.SerializeObject(rowcountResult), globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
                                response = Request.CreateResponse(HttpStatusCode.OK, encryptedResult);
                                return(response);
                            }
                            catch (Exception ex)
                            {
                                ex = (Exception)Activator.CreateInstance(ex.GetType(), "Encrypt Error", ex);
                                throw ex;
                            }
                        }

                        response = Request.CreateResponse(HttpStatusCode.OK, rowcountResult);
                        return(response);
                    }
                }
            }

            catch (Exception ex)
            {
                // error log
                logMessage.memberID  = p.MemberID;
                logMessage.Level     = "ERROR";
                logMessage.Logger    = "CBComUdtMemberItemPurchaseController";
                logMessage.Message   = jsonParam;
                logMessage.Exception = ex.ToString();
                Logging.RunLog(logMessage);

                throw;
            }
        }