// GET api/records/5
        public IHttpActionResult Get(string str)
        {
            if (String.IsNullOrEmpty(str))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            ConverterUrl converter = new ConverterUrl(10);
            long         recordId  = converter.Decode(str);

            HistoryRecord historyRecord = historyRecordService.GetHistoryRecord(recordId);

            if (historyRecord == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            historyRecord.HitCount++;
            historyRecordService.UpdateHistoryRecord(historyRecord);
            historyRecordService.SaveHistoryRecord();

            //var response = Request.CreateResponse(HttpStatusCode.Moved);
            //response.Headers.Location = new Uri(historyRecord.UrlLong);

            return(Redirect(historyRecord.UrlLong));
        }
Пример #2
0
        public void Decode_Strings()
        {
            //Arrange
            long expectedResult1 = 1;
            long expectedResult2 = 12345;
            long expectedResult3 = 540000;
            long expectedResult4 = 1234512345;
            long expectedResult5 = 987777775554654;

            //Act
            long result1 = converter.Decode("20q09ggd9z");
            long result2 = converter.Decode("b3q09ggd9z");
            long result3 = converter.Decode("dltl0k39fp");
            long result4 = converter.Decode("oiob7b032e");
            long result5 = converter.Decode("djnn9jlzff");

            //Assert
            Assert.AreEqual(expectedResult1, result1);
            Assert.AreEqual(expectedResult2, result2);
            Assert.AreEqual(expectedResult3, result3);
            Assert.AreEqual(expectedResult4, result4);
            Assert.AreEqual(expectedResult5, result5);
        }