コード例 #1
0
 public string Post([FromBody] List <string> value)
 {
     try
     {
         PrintJobParser      parser     = new PrintJobParser();
         PrintJob            job        = parser.Parse(value);
         PrintCostCalculator calculator = new PrintCostCalculator();
         return(calculator.Calculate(job));
     }
     catch (PrintJobException)
     {
         return("Parsing error! Please provide valid input");
     }
     catch (Exception)
     {
         return("An unknown error has occurred");
     }
 }
コード例 #2
0
        public async Task <int> GetPrintCost(int photoId)
        {
            if (photoId == 0)
            {
                throw new HttpException(HttpStatusCode.BadRequest, "Please provide a valid photoId.");
            }
            var print = new PhotoPrint
            {
                PhotoId = photoId
            };
            var costCalculator = new PrintCostCalculator(print);

            try
            {
                return(await costCalculator.GetCost());
            }
            catch (NotFoundException e)
            {
                throw new HttpException(HttpStatusCode.NotFound, e.Message);
            }
        }