public IActionResult CreateUrl([FromBody] UrlForCreationDto urlForCreationDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var finalUrl = _mapper.Map <Entities.Url>(urlForCreationDto); _urlShortenerRepository.AddUrl(finalUrl); _urlShortenerRepository.Save(); return(Ok()); }
public IActionResult CreateUser([FromBody] UserForCreationDto userForCreationDto) { _logger.LogInformation( $" FIRSTNAME: {userForCreationDto.FirstName} " + $" LASTNAME: {userForCreationDto.LastName} " + $" BIRTHDATE: {userForCreationDto.BirthDate} THANK YOU!!!!!"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var finalUser = _mapper.Map <Entities.User>(userForCreationDto); _urlShortenerRepository.AddUser(finalUser); _urlShortenerRepository.Save(); return(Ok(finalUser)); }
public IActionResult Get(string route) { var id = Shortener.RecoverId(route); var realUrl = _urlShortenerRepository.FindById(id); if (realUrl == null) { return(NotFound()); } realUrl.Clicks++; realUrl.LastVisit = DateTime.Now; _urlShortenerRepository.Update(realUrl); if (!_urlShortenerRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request")); } return(RedirectPermanent(realUrl.Url)); }