コード例 #1
0
        /// <summary>
        /// Apply holidays
        /// </summary>
        /// <remarks>
        /// http://localhost/Flow.tasks.web/api/users/holiday/cgrant
        /// </remarks>
        /// <param name="name"></param>
        /// <param name="dates"></param>
        /// <returns></returns>
        [HttpPost] public HttpResponseMessage ApplyHoliday(string name, IEnumerable <string> dates)
        {
            try
            {
                var resp = TasksService.ApplyHoliday(new ApplyHolidayRequest {
                    User = name, Type = 2, Holiday = dates
                });

                var json = JsonConvert.SerializeObject(
                    new { resp.HolidayId },
                    Formatting.Indented,
                    new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }
                    );
                var result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new StringContent(json, Encoding.UTF8, "text/plain");

                return(result);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }