public async Task <Agreements> MutacionContratoAsync(AcceptanceAgreements contrato, string token)
 {
     try
     {
         return(await _consumer.MutacionContratoAsync(contrato, token));
     }
     catch { return(null); }
 }
        //Contratos
        public async Task <JsonResult> OnPostContrato([FromBody] AcceptanceAgreements agreementsContratoMarco)
        {
            Participant   = User.Claims.Where(x => x.Type == "Participant").Select(x => x.Value).SingleOrDefault();
            Country       = User.Claims.Where(x => x.Type == "Country").Select(x => x.Value).SingleOrDefault();
            Owner         = User.Claims.Where(x => x.Type == "Owner").Select(x => x.Value).SingleOrDefault();
            Discriminator = User.Claims.Where(x => x.Type == "Discriminator").Select(x => x.Value).SingleOrDefault();
            var token = HttpContext.Session.GetString("token");

            agreementsContratoMarco.Person = Owner;

            var respuesta = await _peopleService.MutacionContratoAsync(agreementsContratoMarco, token);

            if (respuesta != null)
            {
                TipoParticipante                      = Participant;
                registrarClienteTF.User               = new User();
                registrarClienteTF.Registrarse        = new PesonProfile();
                registrarClienteTF.User.Participant   = Participant;
                registrarClienteTF.User.Discriminator = Discriminator;

                if (HttpContext.Session.GetString("CountryPerfil") == null || HttpContext.Session.GetString("CountryPerfil") == "null" || HttpContext.Session.GetString("CountryPerfil") == "")
                {
                    registrarClienteTF.DataPaises = await _globalService.ConsultasCountryTF(new ParamCountry { Id = Int32.Parse(Request.Cookies["Country"]) });

                    HttpContext.Session.SetString("CountryPerfil", JsonConvert.SerializeObject(registrarCliente.DataPaises));
                }
                else
                {
                    registrarClienteTF.DataPaises = JsonConvert.DeserializeObject <ListCountry>(HttpContext.Session.GetString("CountryPerfil"));
                }

                filterInvoice PeopleId = new filterInvoice();
                PeopleId.Id = Owner;
                registrarClienteTF.Perfil = await _peopleService.RegisterById(new ParamProspecto { Filter = PeopleId, Country = int.Parse(Country) }, token);

                if (registrarClienteTF.Perfil.Addresses != null)
                {
                    registrarClienteTF.Cities = await _globalService.ConsultaCitiesTF(new ParamCountry { Id = Int32.Parse(Request.Cookies["Country"]), Region = registrarClienteTF.Perfil.Addresses[0].Region });
                }
                RellenarPerfil();

                registrarClienteTF.AuthRol     = (await _AuthorizationService.AuthorizeAsync(User, "PolicyProfileChange")).Succeeded;
                registrarClienteTF.ContratAuth = (await _AuthorizationService.AuthorizeAsync(User, "PolicyContracts")).Succeeded;
                return(new JsonResult(registrarClienteTF));
            }
            else
            {
                return(new JsonResult(null));
            }
        }
        public async Task <JsonResult> OnPost([FromBody] AcceptanceAgreements contrato)
        {
            Participant = User.Claims.Where(x => x.Type == "Participant").Select(x => x.Value).SingleOrDefault();
            //country = User.Claims.Where(x => x.Type == "Country").Select(x => x.Value).SingleOrDefault();
            Owner = User.Claims.Where(x => x.Type == "Owner").Select(x => x.Value).SingleOrDefault();
            var token = HttpContext.Session.GetString("token");

            contrato.Person = Owner;

            var respuesta = await _peopleService.MutacionContratoAsync(contrato, token);

            #region RefreshToken
            var id = User.Claims.Where(x => x.Type == "Id").Select(x => x.Value).SingleOrDefault();
            var l  = await this._aS.RefreshToken(id, CultureInfo.CurrentCulture.Name, "DEBTOR", token);

            if (l.Error == null)
            {
                HttpContext.Session.SetString("token", l.Token);
            }
            #endregion

            return(new JsonResult(respuesta));
        }
        public async Task <JsonResult> OnPost([FromBody] AcceptanceAgreements contrato)
        {
            Participant = User.Claims.Where(x => x.Type == "Participant").Select(x => x.Value).SingleOrDefault();
            Country     = User.Claims.Where(x => x.Type == "Country").Select(x => x.Value).SingleOrDefault();
            Owner       = User.Claims.Where(x => x.Type == "Owner").Select(x => x.Value).SingleOrDefault();
            var token = HttpContext.Session.GetString("token");

            contrato.Person = Owner;

            var respuesta = await _peopleService.MutacionContratoAsync(contrato, token);

            #region Respuesta
            if (respuesta != null)
            {
                Owner       = User.Claims.Where(x => x.Type == "Owner").Select(x => x.Value).SingleOrDefault();
                Participant = User.Claims.Where(x => x.Type == "Participant").Select(x => x.Value).SingleOrDefault();
                Country     = User.Claims.Where(x => x.Type == "Country").Select(x => x.Value).SingleOrDefault();
                User Contrato = new User();
                Contrato.Person = new Prospecto();

                if (Participant == "SUPPLIER")
                {
                    filterInvoice PeopleId = new filterInvoice();
                    PeopleId.Id = Owner;
                    var contratoTerminos = await _peopleService.ConsultaContratoAsync(new ParamProspecto { Filter = PeopleId, Country = int.Parse(Country) }, token);

                    var Countries = await _globalService.ConsultaBanksTF(new ParamCountry { Id = int.Parse(Country) });

                    if (contratoTerminos != null)
                    {
                        foreach (var contr in contratoTerminos.Agreements)
                        {
                            if (Countries.Entities != null)
                            {
                                foreach (var banks in Countries.Entities)
                                {
                                    if (contrato.Entity == banks.Id && contr.AcceptedAt == null)
                                    {
                                        Contrato.Person.Name = banks.Person.Name;
                                    }
                                }
                                Contrato.Person.Agreements.Add(contr);
                            }
                            if (contrato.Accepted == true && contrato.Abbreviation == "MEMBERSHIP")
                            {
                                Contrato.State = "no_const";
                            }
                        }
                    }
                }

                Contrato.Participant = Participant;
                return(new JsonResult(Contrato));
            }

            #endregion

            #region RefreshToken
            var id = User.Claims.Where(x => x.Type == "Id").Select(x => x.Value).SingleOrDefault();
            var l  = await this._aS.RefreshToken(id, CultureInfo.CurrentCulture.Name, "SUPPLIER", token);

            if (l.Error == null)
            {
                HttpContext.Session.SetString("token", l.Token);
            }
            #endregion


            return(new JsonResult(respuesta));
        }