Пример #1
0
        /// <summary>
        /// Updates or creates a resource based on the resource identifier. The PUT operation is used to update or create a resource by identifier.  If the resource doesn't exist, the resource will be created using that identifier.  Additionally, natural key values cannot be changed using this operation, and will not be modified in the database.  If the resource &quot;id&quot; is provided in the JSON body, it will be ignored as well.
        /// </summary>
        /// <param name="id">A resource identifier specifying the resource to be updated.</param>
        /// <param name="IfMatch">The ETag header value used to prevent the PUT from updating a resource modified by another consumer.</param>
        /// <param name="body">The JSON representation of the &quot;educationContent&quot; resource to be updated.</param>
        /// <returns>A RestSharp <see cref="IRestResponse"/> instance containing the API response details.</returns>
        public IRestResponse PutEducationContent(string id, string IfMatch, EducationContent body)
        {
            var request = new RestRequest("/educationContents/{id}", Method.PUT);

            request.RequestFormat = DataFormat.Json;

            request.AddUrlSegment("id", id);
            // verify required params are set
            if (id == null || body == null)
            {
                throw new ArgumentException("API method call is missing required parameters");
            }
            request.AddHeader("If-Match", IfMatch);
            request.AddBody(body);
            request.Parameters.First(param => param.Type == ParameterType.RequestBody).Name = "application/json";
            var response = client.Execute(request);

            var location = response.Headers.FirstOrDefault(x => x.Name == "Location");

            if (location != null && !string.IsNullOrWhiteSpace(location.Value.ToString()))
            {
                body.id = location.Value.ToString().Split('/').Last();
            }
            return(response);
        }
Пример #2
0
        // 焦點專欄 - 內容
        public ActionResult EducationContent(int?eduTypeID, int?ID, int?pagingID)
        {
            if (!eduTypeID.HasValue || !ID.HasValue)
            {
                return(RedirectToAction("EducationList"));
            }

            //======語系取得========
            string langCd = GetLang();
            //======================

            EducationRepository repo  = new EducationRepository();
            EducationContent    model = repo.GetContentByID((int)eduTypeID, (int)ID, langCd);

            if (pagingID != null)
            {
                model.PagingID = (int)pagingID;
                var pagFirst = model.Data.PagingList.Where(s => s.ID == (int)pagingID).FirstOrDefault();
                if (pagFirst == null)
                {
                    return(RedirectToAction("FocusList", new { eduTypeID }));
                }
                pagFirst.Current = "current";
            }
            else
            {
                if (model.Data.PagingList.Count > 0)
                {
                    model.Data.PagingList.First().Current = "current";
                }
            }

            //=瀏覽記錄====================
            DataTable d_log;
            string    err_msg = "";

            DB.Log_Insert(eduTypeID.ToString(), "Edu");
            d_log = DB.Log_List(ref err_msg, eduTypeID.ToString(), "Edu");
            ViewData["log_count"] = d_log.Rows.Count.ToString();
            //============================

            return(View(model));
        }
Пример #3
0
        /// <summary>
        /// Creates or updates resources based on the natural key values of the supplied resource. The POST operation can be used to create or update resources. In database terms, this is often referred to as an &quot;upsert&quot; operation (insert + update).  Clients should NOT include the resource &quot;id&quot; in the JSON body because it will result in an error (you must use a PUT operation to update a resource by &quot;id&quot;). The web service will identify whether the resource already exists based on the natural key values provided, and update or create the resource appropriately.
        /// </summary>
        /// <param name="body">The JSON representation of the &quot;educationContent&quot; resource to be created or updated.</param>
        /// <returns>A RestSharp <see cref="IRestResponse"/> instance containing the API response details.</returns>
        public IRestResponse PostEducationContents(EducationContent body)
        {
            var request = new RestRequest("/educationContents", Method.POST);

            request.RequestFormat = DataFormat.Json;

            // verify required params are set
            if (body == null)
            {
                throw new ArgumentException("API method call is missing required parameters");
            }
            request.AddBody(body);
            var response = client.Execute(request);

            var location = response.Headers.FirstOrDefault(x => x.Name == "Location");

            if (location != null && !string.IsNullOrWhiteSpace(location.Value.ToString()))
            {
                body.id = location.Value.ToString().Split('/').Last();
            }
            return(response);
        }
Пример #4
0
        /// <summary>
        /// 內容
        /// </summary>
        /// <param name="id"></param>
        /// <param name="lagCode"></param>
        /// <returns></returns>
        public EducationContent GetContentByID(int statesTypeID, int id, string lagCode)
        {
            EducationContent result = new EducationContent();

            using (var db = new TCGDB(_connectionString))
            {
                var sourceList = db.EDU
                                 .AsEnumerable()
                                 .Where(s => (string.IsNullOrEmpty(lagCode) ? true : s.LANG_ID == lagCode) &&
                                        s.STATUS == "Y" && s.CATE_ID == statesTypeID)
                                 .OrderByDescending(o => o.SORT)
                                 .OrderByDescending(s => s.C_DATE)
                                 .ToList();

                var source = sourceList.Where(s => s.ID == id).FirstOrDefault();
                if (source == null)
                {
                    throw new Exception("無法取得活動內容,是否已被移除.");
                }


                result.Data = new EducationData()
                {
                    ID                = source.ID,
                    Title             = source.C_TITLE,
                    PagingList        = GetPagingListByID(source.ID),
                    PublishDateString = source.C_DATE.Value.ToString("yyyy-MM-dd"),
                };
                result.Data.Remark = GetFirstPagingRemark(result.Data.PagingList);
                int dataIndex     = sourceList.IndexOf(source);
                int lastDataIndex = sourceList.Count - 1;
                result.PreviousIDStr = dataIndex == 0 ? "" : sourceList[(dataIndex - 1)].ID.ToString();
                result.NextIDStr     = dataIndex == lastDataIndex ? "" : sourceList[(dataIndex + 1)].ID.ToString();
            }
            result.EduCateInfo = GetEduCateByID(statesTypeID, lagCode);
            return(result);
        }