public Redirect Create(RedirectDto redirect) { String path; do { path = Utils.RandomHex.GetRandomHexNumber(8).ToLower(); }while (PathExists(path)); var hashedPass = BCrypt.Net.BCrypt.HashPassword(redirect.Password); DateTime?fullTime; if (redirect.TTL is null) { fullTime = null; } else { fullTime = DateTime.UtcNow.AddHours(redirect.TTL.Value.Hour).AddMinutes(redirect.TTL.Value.Minute); } var newRedir = new Redirect { ExpirationTime = fullTime, Password = hashedPass, URL = redirect.URL, Path = path }; _redirects.InsertOne(newRedir); _logger.LogInformation($"Inserted redirect: {JsonConvert.SerializeObject(newRedir)}"); return(newRedir); }
public ActionResult <Redirect> Create(RedirectDto redirect) { try { var newRedir = _redirectService.Create(redirect); _deletionService.ProcessRedirect(newRedir); return(Ok(newRedir.Path)); } catch (System.TimeoutException te) { _logger.LogError(te.Message); return(Problem(detail: "Could not connect to MongoDB client", statusCode: (int)HttpStatusCode.InternalServerError)); } }