Beispiel #1
0
        public HttpResponseMessage Get(string productId, string indate)
        {
            HttpResponseMessage message = null;
            vodProgramModel     program = new vodProgramModel();
            string token = HttpContext.Current.Request.Headers["Authorization"].Replace("Bearer ", "").Trim();

            try
            {
                if (dbconn.idbCheck(out dbres))
                {
                    string userCardNo  = string.Empty;
                    string userAdminNo = string.Empty;
                    if (dbconn.checkToken(token, out userCardNo, out userAdminNo))
                    {
                        DataTable dt = dbconn.getTable(appServiceQry._vodProgramList(indate, productId));
                        if (dt.Rows.Count != 0)
                        {
                            List <programDetial> prmList = new List <programDetial>();
                            foreach (DataRow dr in dt.Rows)
                            {
                                programDetial prmDetial = new programDetial();
                                prmDetial.productId      = dr["PRODUCT_ID"].ToString();
                                prmDetial.smsCode        = dr["SMS_CODE"].ToString();
                                prmDetial.contentId      = dr["ID"].ToString();
                                prmDetial.contentNameMon = dr["NAME"].ToString();
                                prmDetial.contentNameEng = dr["NAME_ENGLISH"].ToString();
                                DataTable dtGen = dbconn.getTable(appServiceQry._getGenres(dr["ID"].ToString()));
                                if (dtGen.Rows.Count != 0)
                                {
                                    prmDetial.contentGenres = dtGen.Rows[0]["GENRES"].ToString();
                                }
                                else
                                {
                                    prmDetial.contentGenres = String.Empty;
                                }
                                prmDetial.inDate    = dr["INDATE"].ToString();
                                prmDetial.beginDate = dr["BEGINDATE"].ToString();
                                prmDetial.endDate   = dr["ENDDATE"].ToString();
                                prmDetial.posterUrl = dr["IMAGE_WEB"].ToString().Replace("192.168.10.93", "my.ddishtv.mn:808");
                                string price = "0";
                                switch (productId)
                                {
                                case "17":
                                    price = "3000";
                                    break;

                                case "25":
                                    price = dr["PRICE"].ToString();
                                    break;

                                case "18":
                                    price = "2000";
                                    break;

                                case "19":
                                    price = "1000";
                                    break;

                                default:
                                    price = "0";
                                    break;
                                }
                                prmDetial.contentPrice = price;
                                prmList.Add(prmDetial);
                            }
                            program.isSuccess     = true;
                            program.resultCode    = HttpStatusCode.OK.ToString();
                            program.resultMessage = appConstantValues.MSG_SUCCESS;
                            program.programList   = prmList;
                        }
                        else
                        {
                            program.isSuccess     = false;
                            program.resultCode    = HttpStatusCode.NotFound.ToString();
                            program.resultMessage = appConstantValues.MSG_NOFOUND;
                        }
                    }
                    else
                    {
                        program.isSuccess     = false;
                        program.resultCode    = HttpStatusCode.Unauthorized.ToString();
                        program.resultMessage = appConstantValues.MSG_EXPIRED;
                    }
                }
                else
                {
                    program.isSuccess     = false;
                    program.resultCode    = HttpStatusCode.NotFound.ToString();
                    program.resultMessage = appConstantValues.MSG_INTERNAL_ERROR;
                }
            }
            catch (Exception ex)
            {
                exceptionManager.ManageException(ex, TAG);
                program.isSuccess     = false;
                program.resultCode    = HttpStatusCode.NotFound.ToString();
                program.resultMessage = ex.Message;
            }
            message = Request.CreateResponse(HttpStatusCode.OK, program);
            LogWriter._vodList(TAG, string.Format("IP: [{0}], Request: [{1}], Response: [{2}], Token: [{3}]", httpUtil.GetClientIPAddress(HttpContext.Current.Request), productId, serialzer.Serialize(program), token));
            return(message);
        }
        public HttpResponseMessage Get([FromUri] PagingParameterModel vodPagingModel, string searchValue)
        {
            HttpResponseMessage message = null;
            vodProgramModel     program = new vodProgramModel();
            string token = HttpContext.Current.Request.Headers["Authorization"].Replace("Bearer ", "").Trim();

            try
            {
                if (dbconn.idbCheck(out dbres))
                {
                    string userCardNo  = string.Empty;
                    string userAdminNo = string.Empty;
                    if (dbconn.checkToken(token, out userCardNo, out userAdminNo))
                    {
                        string    _begin = DateTime.Now.ToString(appConstantValues.DATE_FORMAT_LONG);
                        DataTable dt     = dbconn.getTable(appServiceQry._vodProgramSearch(_begin, searchValue));
                        int       count  = dt.Rows.Count;
                        if (count != 0)
                        {
                            int CurrentPage = vodPagingModel.pageNumber;
                            int PageSize    = vodPagingModel.pageSize;
                            int TotalPages  = (int)Math.Ceiling(count / (double)PageSize);


                            List <programDetial> prmList = new List <programDetial>();
                            //prmList.Skip
//dt
                            foreach (DataRow dr in dt.Rows)
                            {
                                programDetial prmDetial = new programDetial();
                                prmDetial.productId      = dr["PRODUCT_ID"].ToString();
                                prmDetial.smsCode        = dr["SMS_CODE"].ToString();
                                prmDetial.contentId      = dr["ID"].ToString();
                                prmDetial.contentNameMon = dr["NAME"].ToString();
                                prmDetial.contentNameEng = dr["NAME_ENGLISH"].ToString();
                                DataTable dtGen = dbconn.getTable(appServiceQry._getGenres(dr["ID"].ToString()));
                                if (dtGen.Rows.Count != 0)
                                {
                                    prmDetial.contentGenres = dtGen.Rows[0]["GENRES"].ToString();
                                }
                                else
                                {
                                    prmDetial.contentGenres = String.Empty;
                                }
                                prmDetial.inDate       = dr["INDATE"].ToString();
                                prmDetial.beginDate    = dr["BEGINDATE"].ToString();
                                prmDetial.endDate      = dr["ENDDATE"].ToString();
                                prmDetial.posterUrl    = dr["IMAGE_WEB"].ToString().Replace("192.168.10.93", "my.ddishtv.mn:808");
                                prmDetial.contentPrice = dr["PRICE"].ToString();
                                prmList.Add(prmDetial);
                            }

                            var items        = prmList.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList();
                            var previousPage = CurrentPage > 1 ? "Yes" : "No";
                            var nextPage     = CurrentPage < TotalPages ? "Yes" : "No";

                            var paginationMetadata = new
                            {
                                totalCount  = count,
                                pageSize    = PageSize,
                                currentPage = CurrentPage,
                                totalPages  = TotalPages,
                                previousPage,
                                nextPage
                            };
                            HttpContext.Current.Response.Headers.Add("X-Paging-Headers", JsonConvert.SerializeObject(paginationMetadata));
                            program.isSuccess     = true;
                            program.resultCode    = HttpStatusCode.OK.ToString();
                            program.resultMessage = appConstantValues.MSG_SUCCESS;
                            program.programList   = items;
                        }
                        else
                        {
                            program.isSuccess     = false;
                            program.resultCode    = HttpStatusCode.NotFound.ToString();
                            program.resultMessage = appConstantValues.MSG_NOFOUND;
                        }
                    }
                    else
                    {
                        program.isSuccess     = false;
                        program.resultCode    = HttpStatusCode.Unauthorized.ToString();
                        program.resultMessage = appConstantValues.MSG_EXPIRED;
                    }
                }
                else
                {
                    program.isSuccess     = false;
                    program.resultCode    = HttpStatusCode.NotFound.ToString();
                    program.resultMessage = appConstantValues.MSG_INTERNAL_ERROR;
                }
            }
            catch (Exception ex)
            {
                exceptionManager.ManageException(ex, TAG);
                program.isSuccess     = false;
                program.resultCode    = HttpStatusCode.NotFound.ToString();
                program.resultMessage = ex.Message;
            }
            message = Request.CreateResponse(HttpStatusCode.OK, program);
            LogWriter._vodList(TAG, string.Format("IP: [{0}], Request: [{1}], Response: [{2}], Token: [{3}]", httpUtil.GetClientIPAddress(HttpContext.Current.Request), searchValue, serializer.Serialize(program), token));
            return(message);
        }