Example #1
0
        public Response InsertIfNotexist(Core.Entity.Client client)
        {
            try
            {
                StoreProcedure storeProcedure = new StoreProcedure("weco.CLIENTE_InsertIfNotexist");
                storeProcedure.AddParameter("@CLIE_CORREO_ELECTRONICO_VC", client.Email);
                storeProcedure.AddParameter("@CLIE_CI_VC", client.Ci);
                storeProcedure.AddParameter("@CLIE_CI_EXPEDICION_VC", client.CiExpedition);
                storeProcedure.AddParameter("@CLIE_CLAVE_VC", client.Password);
                storeProcedure.AddParameter("@CLIE_TERMINOS_Y_CONDICIONES_ACEPTADOS_BT", client.AcceptTerms);
                storeProcedure.AddParameter("@CLIE_TOKEN_VERIFICACION_EMAIL_VC", client.VerificationTokenEmail);
                storeProcedure.AddParameter("@CLIE_ROL_IN", 1);
                storeProcedure.AddParameter("@CLIE_USUARIO_CREACION_VC", client.CreationUser);

                DataTable dataTable = storeProcedure.ReturnData(_connection, _timeOut);
                Logger.Debug("StoreProcedure: {0} DataTable: {1}", SerializeJson.ToObject(storeProcedure), SerializeJson.ToObject(dataTable));

                if (storeProcedure.Error.Length <= 0)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        if (dataTable.Rows[0]["RESULTADO"].ToString().Equals("00"))
                        {
                            Core.Entity.Client result = new Core.Entity.Client
                            {
                                Id                     = Convert.ToInt64(dataTable.Rows[0]["CLIE_CLIENTE_ID_BI"]),
                                Email                  = dataTable.Rows[0]["CLIE_CORREO_ELECTRONICO_VC"].ToString(),
                                Ci                     = dataTable.Rows[0]["CLIE_CI_VC"].ToString(),
                                CiExpedition           = dataTable.Rows[0]["CLIE_CI_EXPEDICION_VC"].ToString(),
                                VerificationTokenEmail = dataTable.Rows[0]["CLIE_TOKEN_VERIFICACION_EMAIL_VC"].ToString(),
                            };

                            return(Response.Success(result));
                        }
                        else
                        {
                            Logger.Debug("Message: {0} DataTable: {1}", Response.CommentMenssage("AlreadyRegisteredEmail"), SerializeJson.ToObject(dataTable));
                            return(Response.Error(dataTable, "AlreadyRegisteredEmail"));
                        }
                    }
                    else
                    {
                        Logger.Debug("Message: {0} DataTable: {1}", Response.CommentMenssage("Sql"), SerializeJson.ToObject(dataTable));
                        return(Response.Error(dataTable, "Sql"));
                    }
                }
                else
                {
                    Logger.Error("Message: {0} StoreProcedure.Error: {1}", Response.CommentMenssage("Sql"), storeProcedure.Error);
                    return(Response.Error(storeProcedure.Error, "Sql"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Message: {0} Exception: {1}", ex.Message, SerializeJson.ToObject(ex));
                return(Response.Error(ex, "Error"));
            }
        }
Example #2
0
 public Response UpdateRegistrationComplete(Core.Entity.Client client, string userModification)
 {
     try
     {
         StoreProcedure storeProcedure = new StoreProcedure("weco.CLIENTE_UpdateRegistrationComplete");
         storeProcedure.AddParameter("@CLIE_CORREO_ELECTRONICO_VC", client.Email);
         storeProcedure.AddParameter("@CLIE_NOMBRE_COMPLETO_VC", client.NameComplete);
         storeProcedure.AddParameter("@CLIE_GENERO_VC", client.Gender);
         storeProcedure.AddParameter("@CLIE_FECHA_NACIMIENTO_DT", client.Birthdate);
         storeProcedure.AddParameter("@CLIE_EDAD_IN", client.Age);
         storeProcedure.AddParameter("@CLIE_DEPARTAMENTO_VC", client.Department);
         storeProcedure.AddParameter("@CLIE_CIUDAD_VC", client.City);
         storeProcedure.AddParameter("@CLIE_DIRECCION_VC", client.Address);
         storeProcedure.AddParameter("@CLIE_NUMERO_CELULAR_VC", client.CellPhone);
         storeProcedure.AddParameter("@CLIE_NUMERO_FIJO_VC", client.Phone);
         storeProcedure.AddParameter("@CLIE_NIVEL_EDUCACION_VC", client.EducationLevel);
         storeProcedure.AddParameter("@CLIE_DISCAPACIDAD_BT", client.Disability);
         storeProcedure.AddParameter("@CLIE_TIPO_DISCAPACIDAD_VC", client.TypeDisability);
         storeProcedure.AddParameter("@CLIE_NOMBRE_REFERENCIA_VC", client.ReferenceName);
         storeProcedure.AddParameter("@CLIE_CELULAR_REFERENCIA_VC", client.ReferencePhone);
         storeProcedure.AddParameter("@CLIE_USUARIO_MODIFICACION_VC", userModification);
         DataTable dataTable = storeProcedure.ReturnData(_connection, _timeOut);
         Logger.Debug("StoreProcedure: {0} DataTable: {1}", SerializeJson.ToObject(storeProcedure), SerializeJson.ToObject(dataTable));
         if (storeProcedure.Error.Length <= 0)
         {
             if (dataTable.Rows.Count > 0)
             {
                 if (Convert.ToInt32(dataTable.Rows[0]["@@ROWCOUNT"]) > 0)
                 {
                     return(Response.Success(Convert.ToInt64(dataTable.Rows[0]["@@ROWCOUNT"].ToString())));
                 }
                 else
                 {
                     Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("ErrorRegistrationComplete"), SerializeJson.ToObject(dataTable));
                     return(Response.Error(null, "ErrorRegistrationComplete"));
                 }
             }
             else
             {
                 Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("Sql"), SerializeJson.ToObject(dataTable));
                 return(Response.Error(null, "Sql"));
             }
         }
         else
         {
             Logger.Error("Message: {0}; StoreProcedure.Error: {1}", Response.CommentMenssage("Sql"), storeProcedure.Error);
             return(Response.Error(storeProcedure.Error, "Sql"));
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Message: {0} Exception: {1}", ex.Message, SerializeJson.ToObject(ex));
         return(Response.Error(ex, "Error"));
     }
 }
Example #3
0
        public Response RefreshTokenUpdate(string email, string ipAddress, string refreshToken, string newRefreshToken)
        {
            try
            {
                StoreProcedure storeProcedure = new StoreProcedure("weco.TOKEN_ACTUALIZACION_RefreshTokenUpdate");
                storeProcedure.AddParameter("@CLIE_CORREO_ELECTRONICO_VC", email);
                storeProcedure.AddParameter("@TOAC_IP_REVOCACION_TOKEN_VC", ipAddress);
                storeProcedure.AddParameter("@TOAC_TOKEN_VC", refreshToken);
                storeProcedure.AddParameter("@TOAC_TOKEN_REEMPLAZADO_TOKEN_VC", newRefreshToken);

                DataTable dataTable = storeProcedure.ReturnData(_connection, _timeOut);
                Logger.Debug("StoreProcedure: {0} DataTable: {1}", SerializeJson.ToObject(storeProcedure), SerializeJson.ToObject(dataTable));

                if (storeProcedure.Error.Length <= 0)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        if (dataTable.Rows[0]["RESULTADO"].ToString().Equals("00"))
                        {
                            Core.Entity.Client result = new Core.Entity.Client
                            {
                                NameComplete     = dataTable.Rows[0]["CLIE_NOMBRE_COMPLETO_VC"].ToString(),
                                Email            = dataTable.Rows[0]["CLIE_CORREO_ELECTRONICO_VC"].ToString(),
                                Role             = Convert.ToInt32(dataTable.Rows[0]["CLIE_ROL_IN"]) == 0 ? Role.Admin : Role.User,
                                IsVerified       = Convert.ToBoolean(dataTable.Rows[0]["CLIE_ESTADO_VERIFICACION_BT"]),
                                CompleteRegister = Convert.ToBoolean(dataTable.Rows[0]["CLIE_REGISTRO_COMPLETO_BT"])
                            };

                            return(Response.Success(result));
                        }
                        else
                        {
                            Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("ErrorGeneredTokeRefresh"), SerializeJson.ToObject(dataTable));
                            return(Response.Error(null, "ErrorGeneredTokeRefresh"));
                        }
                    }
                    else
                    {
                        Logger.Debug("Message: {0} DataTable: {1}", Response.CommentMenssage("Sql"), SerializeJson.ToObject(dataTable));
                        return(Response.Error(dataTable, "Sql"));
                    }
                }
                else
                {
                    Logger.Error("Message: {0} StoreProcedure.Error: {1}", Response.CommentMenssage("Sql"), storeProcedure.Error);
                    return(Response.Error(storeProcedure.Error, "Sql"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Message: {0} Exception: {1}", ex.Message, SerializeJson.ToObject(ex));
                return(Response.Error(ex, "Error"));
            }
        }
Example #4
0
        public Response UpdateClientForgotPassword(string email, string resetToken)
        {
            try
            {
                StoreProcedure storeProcedure = new StoreProcedure("weco.CLIENTE_UpdateClientForgotPassword");
                storeProcedure.AddParameter("@CLIE_CORREO_ELECTRONICO_VC", email);
                storeProcedure.AddParameter("@CLIE_RESTABLECER_TOKEN_VERIFICACION_EMAIL_VC", resetToken);
                storeProcedure.AddParameter("@CLIE_FECHA_EXPIRACION_TOKEN_RESTABLECER_DT", DateTime.UtcNow.AddDays(1));
                DataTable dataTable = storeProcedure.ReturnData(_connection, _timeOut);
                Logger.Debug("StoreProcedure: {0} DataTable: {1}", SerializeJson.ToObject(storeProcedure), SerializeJson.ToObject(dataTable));
                if (storeProcedure.Error.Length <= 0)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        if (dataTable.Rows[0]["RESULTADO"].ToString().Equals("00"))
                        {
                            Core.Entity.Client result = new Core.Entity.Client
                            {
                                Email      = dataTable.Rows[0]["CLIE_CORREO_ELECTRONICO_VC"].ToString(),
                                ResetToken = dataTable.Rows[0]["CLIE_RESTABLECER_TOKEN_VERIFICACION_EMAIL_VC"].ToString()
                            };

                            return(Response.Success(result));
                        }
                        else
                        {
                            Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("ErrorGeneredTokeRefresh"), SerializeJson.ToObject(dataTable));
                            return(Response.Error(null, "ErrorGeneredTokeRefresh"));
                        }
                    }
                    else
                    {
                        Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("NotLogin"), SerializeJson.ToObject(dataTable));
                        return(Response.Error(null, "NotLogin"));
                    }
                }
                else
                {
                    Logger.Error("Message: {0}; StoreProcedure.Error: {1}", Response.CommentMenssage("Sql"), storeProcedure.Error);
                    return(Response.Error(storeProcedure.Error, "Sql"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Message: {0} Exception: {1}", ex.Message, SerializeJson.ToObject(ex));
                return(Response.Error(ex, "Error"));
            }
        }
Example #5
0
        public Response GetClientCompleteRegistration(string email)
        {
            try
            {
                StoreProcedure storeProcedure = new StoreProcedure("weco.CLIENTE_UpdateByEmailForChangePassword");
                storeProcedure.AddParameter("@CLIE_CORREO_ELECTRONICO_VC", email);
                DataTable dataTable = storeProcedure.ReturnData(_connection, _timeOut);
                Logger.Debug("StoreProcedure: {0} DataTable: {1}", SerializeJson.ToObject(storeProcedure), SerializeJson.ToObject(dataTable));
                if (storeProcedure.Error.Length <= 0)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        if (dataTable.Rows[0]["RESULTADO"].ToString().Equals("00"))
                        {
                            Core.Entity.Client result = new Core.Entity.Client
                            {
                                Email = dataTable.Rows[0]["CLIE_CORREO_ELECTRONICO_VC"].ToString(),
                            };

                            return(Response.Success(result));
                        }
                        else
                        {
                            Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("ErrorResetPassword"), SerializeJson.ToObject(dataTable));
                            return(Response.Error(null, "ErrorResetPassword"));
                        }
                    }
                    else
                    {
                        Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("NotLogin"), SerializeJson.ToObject(dataTable));
                        return(Response.Error(null, "NotLogin"));
                    }
                }
                else
                {
                    Logger.Error("Message: {0}; StoreProcedure.Error: {1}", Response.CommentMenssage("Sql"), storeProcedure.Error);
                    return(Response.Error(storeProcedure.Error, "Sql"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Message: {0} Exception: {1}", ex.Message, SerializeJson.ToObject(ex));
                return(Response.Error(ex, "Error"));
            }
        }
Example #6
0
        public IActionResult PreRegistration([FromBody] PreRegistrationRequest preRegistrationRequest)
        {
            Logger.Debug("Request: {0}", Framework.Common.SerializeJson.ToObject(preRegistrationRequest));
            DateTime dateRequest   = DateTime.Now;
            var      response      = new IResponse <PreRegistrationResponse>();
            string   correlationId = string.Empty;

            try
            {
                #region Authorization Usuario y Contraseña
                if (string.IsNullOrEmpty(Request.Headers["Authorization"]))
                {
                    var validate = Models.Response.Error(null, "NotAuthenticated");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(Unauthorized(response));
                }

                AuthenticationHeaderValue authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
                var credentials = Encoding.UTF8.GetString(Convert.FromBase64String(authHeader.Parameter)).Split(':');
                correlationId = Request.Headers["Correlation-Id"].ToString();

                Core.Entity.User user = new Core.Entity.User()
                {
                    Public   = preRegistrationRequest.PublicToken,
                    UserName = credentials[0],
                    Password = credentials[1]
                };
                var userAuthenticate = _user.Authenticate(user);
                if (userAuthenticate.Data == null)
                {
                    var validate = Models.Response.Error("NotAuthenticated");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(Unauthorized(response));
                }
                Core.Entity.UserPolicy userPolicy = new Core.Entity.UserPolicy()
                {
                    AppUserId = preRegistrationRequest.AppUserId,
                    IdUser    = ((Core.Entity.User)userAuthenticate.Data).Id
                };
                Core.Entity.Policy policy = new Core.Entity.Policy()
                {
                    Name = Request.Path.Value
                };
                var userPolicyAuthorize = _userPolicy.Authorize(userPolicy, policy);
                if (userPolicyAuthorize.Data == null)
                {
                    var validate = Models.Response.Error("NotUnauthorized");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(Unauthorized(response));
                }
                #endregion

                if (!Framework.Common.Tools.WellWrittenEmail(preRegistrationRequest.Email))
                {
                    var validate = Models.Response.Error("InvalidEmail");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(BadRequest(response));
                }

                if (preRegistrationRequest.Password != preRegistrationRequest.ConfirmPassword)
                {
                    var validate = Models.Response.Error("PasswordNotConfirm");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(BadRequest(response));
                }

                var passwordEncrypted     = BC.HashPassword(preRegistrationRequest.Password);
                Core.Entity.Client client = new Core.Entity.Client()
                {
                    Email                  = preRegistrationRequest.Email,
                    Ci                     = preRegistrationRequest.Ci,
                    CiExpedition           = preRegistrationRequest.CiExpedition,
                    Password               = passwordEncrypted,
                    AcceptTerms            = preRegistrationRequest.AcceptTerms,
                    VerificationTokenEmail = Framework.Common.Tools.RandomTokenString(),
                    CreationUser           = preRegistrationRequest.AppUserId
                };
                var clientCreateAcountInsert = _client.InsertIfNotexist(client);
                if (clientCreateAcountInsert.Data == null)
                {
                    response.Data    = null;
                    response.Message = clientCreateAcountInsert.Message;
                    response.State   = clientCreateAcountInsert.State;
                    return(BadRequest(response));
                }
                var newClient = (Core.Entity.Client)clientCreateAcountInsert.Data;


                var linkToken = _configuration.GetValue <string>("Connectors_Email:link") + string.Format("?token={0}", newClient.VerificationTokenEmail);
                var withOriginMessageVerificationEmail    = _configuration.GetValue <string>("Connectors_Email:WithOriginMessageVerificationEmail");
                var withoutOriginMessageVerificationEmail = _configuration.GetValue <string>("Connectors_Email:WithoutOriginMessageVerificationEmail");
                _emailmanager.SendEmail(newClient.Email, "Verificacion de Correo", withOriginMessageVerificationEmail, withoutOriginMessageVerificationEmail, "VERIFICACIÓN DE CORREO PARA ACTIVAR SU CUENTA", Request.Headers["origin"], linkToken, newClient.VerificationTokenEmail);

                response.Data = new PreRegistrationResponse
                {
                    Email = newClient.Email,
                    Ci    = newClient.Ci,
                };
                response.Message = Models.Response.CommentMenssage("PreRegistredCompleted");
                response.State   = "000";
                return(Ok(response));
            }
            catch (Exception ex)
            {
                Logger.Error("Message: {0}; Exception: {1}", ex.Message, Framework.Common.SerializeJson.ToObject(ex));
                response.Data    = null;
                response.Message = "Error General";
                response.State   = "099";
                return(BadRequest(response));
            }
            finally
            {
                DateTime dateResponse = DateTime.Now;
                Core.Entity.ConsumptionHistory consumptionHistory = new Core.Entity.ConsumptionHistory
                {
                    ApiName       = Request.Path.Value,
                    Host          = Dns.GetHostName() + ":" + Request.Host.Port,
                    CorrelationId = correlationId,
                    AppUserId     = preRegistrationRequest.AppUserId,
                    Request       = Framework.Common.SerializeJson.ToObject(preRegistrationRequest),
                    DateRequest   = dateRequest,
                    Response      = Framework.Common.SerializeJson.ToObject(response),
                    DateResponse  = dateResponse,
                    CodeResponse  = response.State
                };
                _consumptionHistory.Insert(consumptionHistory);
                Logger.Debug("Request: {0} Response: {1}", preRegistrationRequest, response);
            }
        }
Example #7
0
        public Response GetClientValitated(string email, string password)
        {
            try
            {
                StoreProcedure storeProcedure = new StoreProcedure("weco.CLIENTE_GetClientValitated");
                storeProcedure.AddParameter("@CLIE_CORREO_ELECTRONICO_VC", email);
                storeProcedure.AddParameter("@CLIE_CLAVE_VC", password);
                DataTable dataTable = storeProcedure.ReturnData(_connection, _timeOut);
                Logger.Debug("StoreProcedure: {0} DataTable: {1}", SerializeJson.ToObject(storeProcedure), SerializeJson.ToObject(dataTable));
                if (storeProcedure.Error.Length <= 0)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        if (dataTable.Rows[0]["RESULTADO"].ToString().Equals("00"))
                        {
                            Core.Entity.Client result = new Core.Entity.Client
                            {
                                NameComplete     = dataTable.Rows[0]["CLIE_NOMBRE_COMPLETO_VC"].ToString(),
                                Email            = dataTable.Rows[0]["CLIE_CORREO_ELECTRONICO_VC"].ToString(),
                                Password         = dataTable.Rows[0]["CLIE_CLAVE_VC"].ToString(),
                                Role             = Convert.ToInt32(dataTable.Rows[0]["CLIE_ROL_IN"]) == 0 ? Role.Admin : Role.User,
                                IsVerified       = Convert.ToBoolean(dataTable.Rows[0]["CLIE_ESTADO_VERIFICACION_BT"]),
                                CompleteRegister = Convert.ToBoolean(dataTable.Rows[0]["CLIE_REGISTRO_COMPLETO_BT"]),
                                CurrentModule    = Convert.ToInt32(dataTable.Rows[0]["MODULO_ACTUAL"])
                            };

                            if (BC.Verify(password, result.Password))
                            {
                                return(Response.Success(result));
                            }
                            else
                            {
                                Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("NotLogin"), SerializeJson.ToObject(dataTable));
                                return(Response.Error(null, "NotLogin"));
                            }
                        }
                        else
                        {
                            if (dataTable.Rows[0]["RESULTADO"].ToString().Equals("02"))
                            {
                                Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("AccountNotValidated"), SerializeJson.ToObject(dataTable));
                                return(Response.Error(null, "AccountNotValidated"));
                            }
                            else
                            {
                                Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("NotLogin"), SerializeJson.ToObject(dataTable));
                                return(Response.Error(null, "NotLogin"));
                            }
                        }
                    }
                    else
                    {
                        Logger.Error("Message: {0}; dataTable: {1}", Response.CommentMenssage("NotLogin"), SerializeJson.ToObject(dataTable));
                        return(Response.Error(null, "NotLogin"));
                    }
                }
                else
                {
                    Logger.Error("Message: {0}; StoreProcedure.Error: {1}", Response.CommentMenssage("Sql"), storeProcedure.Error);
                    return(Response.Error(storeProcedure.Error, "Sql"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Message: {0} Exception: {1}", ex.Message, SerializeJson.ToObject(ex));
                return(Response.Error(ex, "Error"));
            }
        }
Example #8
0
        public IActionResult RegistrationComplete([FromBody] RegistrationCompleteRequest registrationCompleteRequest)
        {
            Logger.Debug("Request: {0}", Framework.Common.SerializeJson.ToObject(registrationCompleteRequest));
            DateTime dateRequest   = DateTime.Now;
            var      response      = new IResponse <RegistrationCompleteResponse>();
            string   correlationId = string.Empty;

            try
            {
                #region Authorization Usuario y Contraseña
                if (string.IsNullOrEmpty(Request.Headers["Authorization"]))
                {
                    var validate = Models.Response.Error(null, "NotAuthenticated");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(Unauthorized(response));
                }

                //AuthenticationHeaderValue authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
                //var credentials = Encoding.UTF8.GetString(Convert.FromBase64String(authHeader.Parameter)).Split(':');
                correlationId = Request.Headers["Correlation-Id"].ToString();

                Core.Entity.User user = new Core.Entity.User()
                {
                    Public   = registrationCompleteRequest.PublicToken,
                    UserName = registrationCompleteRequest.UserAplication,
                    Password = registrationCompleteRequest.PasswordAplication
                };
                var userAuthenticate = _user.Authenticate(user);
                if (userAuthenticate.Data == null)
                {
                    var validate = Models.Response.Error("NotAuthenticated");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(Unauthorized(response));
                }
                Core.Entity.UserPolicy userPolicy = new Core.Entity.UserPolicy()
                {
                    AppUserId = registrationCompleteRequest.AppUserId,
                    IdUser    = ((Core.Entity.User)userAuthenticate.Data).Id
                };
                Core.Entity.Policy policy = new Core.Entity.Policy()
                {
                    Name = Request.Path.Value
                };
                var userPolicyAuthorize = _userPolicy.Authorize(userPolicy, policy);
                if (userPolicyAuthorize.Data == null)
                {
                    var validate = Models.Response.Error("NotUnauthorized");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(Unauthorized(response));
                }
                #endregion

                AuthenticationHeaderValue authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
                var credentialToken        = authHeader.Parameter;
                var responsetokenValidated = _tokenManager.GetPrincipalFromExpiredToken(credentialToken);

                if (responsetokenValidated.Data == null)
                {
                    response.Data    = null;
                    response.Message = responsetokenValidated.Message;
                    response.State   = responsetokenValidated.State;
                    return(BadRequest(response));
                }
                var principal   = (ClaimsPrincipal)responsetokenValidated.Data;
                var claimList   = principal.Claims.ToList();
                var verifyEmail = claimList[2].Value;

                if (!verifyEmail.Equals(registrationCompleteRequest.Email.Trim()))
                {
                    var validate = Models.Response.Error("ClientNotSession");
                    response.Data    = null;
                    response.Message = validate.Message;
                    response.State   = validate.State;
                    return(BadRequest(response));
                }

                /*if (registrationCompleteRequest.Age <= 18 && (DateTime.Now.Year - registrationCompleteRequest.Birthdate.Year) <= 18)
                 * {
                 *  var validate = Models.Response.Error("UserNotAgeApropiate");
                 *  response.Data = null;
                 *  response.Message = validate.Message;
                 *  response.State = validate.State;
                 *  return BadRequest(response);
                 * }*/
                Core.Entity.Client client = new Core.Entity.Client()
                {
                    Email            = registrationCompleteRequest.Email,
                    NameComplete     = registrationCompleteRequest.NameComplete,
                    Gender           = registrationCompleteRequest.Gender,
                    Birthdate        = registrationCompleteRequest.Birthdate,
                    Age              = registrationCompleteRequest.Age,
                    Department       = registrationCompleteRequest.Department,
                    City             = registrationCompleteRequest.City,
                    Address          = registrationCompleteRequest.Address,
                    CellPhone        = registrationCompleteRequest.CellPhone,
                    Phone            = registrationCompleteRequest.Phone,
                    EducationLevel   = registrationCompleteRequest.EducationLevel,
                    Disability       = registrationCompleteRequest.Disability,
                    TypeDisability   = registrationCompleteRequest.TypeDisability,
                    ReferenceName    = registrationCompleteRequest.ReferenceName,
                    ReferencePhone   = registrationCompleteRequest.ReferencePhone,
                    ModificationUser = registrationCompleteRequest.AppUserId
                };

                var clientCreateAcountInsert = _client.UpdateRegistrationComplete(client, registrationCompleteRequest.AppUserId);
                if (!(Convert.ToInt32(clientCreateAcountInsert.Data) > 0))
                {
                    response.Data    = null;
                    response.Message = clientCreateAcountInsert.Message;
                    response.State   = clientCreateAcountInsert.State;
                    return(BadRequest(response));
                }

                response.Data = new RegistrationCompleteResponse
                {
                    Email = registrationCompleteRequest.Email,
                    RegistrationComplete = true,
                    NameComplete         = registrationCompleteRequest.NameComplete
                };
                response.Message = Models.Response.CommentMenssage("RegistrationCompleted");
                response.State   = "000";
                return(Ok(response));
            }
            catch (Exception ex)
            {
                Logger.Error("Message: {0}; Exception: {1}", ex.Message, Framework.Common.SerializeJson.ToObject(ex));
                response.Data    = null;
                response.Message = "Error General";
                response.State   = "099";
                return(BadRequest(response));
            }
            finally
            {
                DateTime dateResponse = DateTime.Now;
                Core.Entity.ConsumptionHistory consumptionHistory = new Core.Entity.ConsumptionHistory
                {
                    ApiName       = Request.Path.Value,
                    Host          = Dns.GetHostName() + ":" + Request.Host.Port,
                    CorrelationId = correlationId,
                    AppUserId     = registrationCompleteRequest.AppUserId,
                    Request       = Framework.Common.SerializeJson.ToObject(registrationCompleteRequest),
                    DateRequest   = dateRequest,
                    Response      = Framework.Common.SerializeJson.ToObject(response),
                    DateResponse  = dateResponse,
                    CodeResponse  = response.State
                };
                _consumptionHistory.Insert(consumptionHistory);
                Logger.Debug("Request: {0} Response: {1}", registrationCompleteRequest, response);
            }
        }