コード例 #1
0
 public async Task<FormattedContentResult<HotelRequest>> Hello(LoginRequest request)
 {
     if (HttpContext.Current.Request.ContentType.Contains("json")) throw new Exception("No Json allowed, ContentType must be: text/xml");
     HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
     var response =
         new HotelRequest
         {
             Security = new Security { UserName = "******", Token = "A9-SDTES-NIC0-WR132-412422" },
             City = "Stockholm",
             CheckInDate = DateTime.Now,
             CheckOutDate = DateTime.Now.AddDays(12),
             CustomerInfo = new CustomerInfo { NumberOfAdults = 2 }
         };
     return Content(HttpStatusCode.OK, response,
         Configuration.Formatters.XmlFormatter);
 }
コード例 #2
0
 public async Task<FormattedContentResult<HotelResponse>> GetHotels(HotelRequest request)
 {
     if (HttpContext.Current.Request.ContentType.Contains("json")) throw new Exception("No Json allowed, ContentType must be: text/xml");
     HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
     HotelResponse response;
     try
     {
         if (request.Security.Token == null)
         {
             response = new HotelResponse
             {
                 Status = new Status
                 {
                     Error =
                         "Missing Token: You first have to login with your credentials (UserName: DiscoCat, Password: NinjaMoves)"
                 }
             };
             return Content(HttpStatusCode.OK, response,
                 Configuration.Formatters.XmlFormatter);
         }
         if (request.Security.UserName != "DiscoCat" || request.Security.Token != "A9-SDTES-NIC0-WR132-412422")
         {
             response = new HotelResponse
             {
                 Status = new Status
                 {
                     Error =
                         "Illegal Token: You first have to login with your credentials (UserName: DiscoCat, Password: NinjaMoves)"
                 }
             };
             return Content(HttpStatusCode.OK, response,
                 Configuration.Formatters.XmlFormatter);
         }
         response = new HotelResponse
         {
             Status = new Status { Success = true },
             Hotels = new[]
             {
                 new Hotel
                 {
                     Name = string.Format("{0} Hilton", request.City),
                     NumberOfPeople = request.CustomerInfo.NumberOfAdults,
                 },
                 new Hotel
                 {
                     Name = string.Format("Best Western {0}", request.City),
                     NumberOfPeople = request.CustomerInfo.NumberOfAdults,
                 },
                 new Hotel
                 {
                     Name = string.Format("{0} Marriott Hotel", request.City),
                     NumberOfPeople = request.CustomerInfo.NumberOfAdults,
                 }
             }
         };
         return Content(HttpStatusCode.OK, response,
             Configuration.Formatters.XmlFormatter);
     }
     catch (Exception ex)
     {
         response =
             new HotelResponse
             {
                 Status = new Status
                 {
                     Error =
                         "Something went terribly wrong!"
                 }
             };
         return Content(HttpStatusCode.OK, response,
             Configuration.Formatters.XmlFormatter);
     }
 }