public HttpResponseMessage ResetPassword(Earthwatcher earthwatcher, HttpRequestMessage<Earthwatcher> request) { if (earthwatcher != null) { try { //Date var encodedDateBytes = System.Convert.FromBase64String(earthwatcher.Region); string encodedDate = System.Text.Encoding.UTF8.GetString(encodedDateBytes); DateTime date = DateTime.MinValue; DateTime.TryParse(encodedDate, out date); if (date == DateTime.MinValue || date.AddDays(1) < DateTime.Now) { var response = new HttpResponseMessage(HttpStatusCode.BadRequest); return response; } var earthwatcherDb = earthwatcherRepository.GetEarthwatcherByGuid(earthwatcher.Guid); if (earthwatcherDb == null) { var response = new HttpResponseMessage(HttpStatusCode.NotFound); return response; } PasswordResource pwd = new PasswordResource(); earthwatcherDb.Password = earthwatcher.Password; pwd.GenerateAndUpdatePassword(earthwatcherDb); return new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; } catch (Exception ex) { return new HttpResponseMessage() { StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = ex.Message }; } } return new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }; }