Пример #1
0
        public async Task <IActionResult> UpdateOpportunityInfo([FromBody] OpportunityPartnerReq model)
        {
            ManageOpportunityReq  request  = new ManageOpportunityReq();
            OpportunityPartnerRes response = new OpportunityPartnerRes();

            try
            {
                if (!ModelState.IsValid)
                {
                    response.ResponseStatus.Status       = "Failure";
                    response.ResponseStatus.ErrorMessage = "Request is not valid";
                    return(BadRequest(ModelState));
                }
                else
                {
                    if (model != null)
                    {
                        request = SetOpportunityInfoWithModel(model);

                        IntegrationLoginResponse objTokenResponse = loginProviders.GetIntegrationToken(request.CredentialInfo).Result;
                        if (string.Compare(objTokenResponse.Message, "Success", true) == 0 && objTokenResponse.Token != "")
                        {
                            request.CreatedUser           = objTokenResponse.UserInfo.UserName;
                            request.Application           = request.CredentialInfo.Source;
                            request.Token                 = objTokenResponse.Token;
                            request.LoggedInUserContactId = objTokenResponse.UserInfo.Contact_Id;

                            response = quoteProviders.UpdatePartnerOpportunityDetails(request, objTokenResponse.Token).Result;

                            if (response.ResponseStatus != null && !string.IsNullOrEmpty(response.ResponseStatus.Status) && response.ResponseStatus.Status.ToLower() == "failed")
                            {
                                return(BadRequest(response.ResponseStatus));
                            }
                        }
                        else
                        {
                            return(Unauthorized());
                        }
                    }
                    else
                    {
                        response.ResponseStatus.Status       = "Failure";
                        response.ResponseStatus.ErrorMessage = "Opportunity details can not be save due to error.";
                        return(BadRequest(response.ResponseStatus));
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = "An error occurs " + ex.Message.ToString();
                return(BadRequest(response.ResponseStatus));
            }
            return(Ok(new { Status = response.ResponseStatus.Status, ErrorMessage = response.ResponseStatus.ErrorMessage, StatusMessage = response.ResponseStatus.StatusMessage, Id = request.OpportunityInfo.OpportunityId }));
        }
Пример #2
0
        public async Task <IActionResult> CreateUpdateAgentInfo([FromBody] AgentPartnerReq model)
        {
            ManageAgentReq request  = new ManageAgentReq();
            var            response = new ManageAgentRes();

            try
            {
                if (!ModelState.IsValid)
                {
                    response.ResponseStatus.Status       = "Failure";
                    response.ResponseStatus.ErrorMessage = "Request is not valid";
                    return(BadRequest(ModelState));
                }
                else
                {
                    if (model != null)
                    {
                        request = SetAgentInfoWithModel(model);
                        IntegrationLoginResponse objTokenResponse = loginProviders.GetIntegrationToken(request.CredentialInfo).Result;
                        if (string.Compare(objTokenResponse.Message, "Success", true) == 0 && objTokenResponse.Token != "")
                        {
                            request.CreatedUser           = objTokenResponse.UserInfo.UserName;
                            request.Application           = request.CredentialInfo.Source;
                            request.Token                 = objTokenResponse.Token;
                            request.LoggedInUserContactId = objTokenResponse.UserInfo.Contact_Id;

                            var countryInfo = agentProviders.GetPartnerCountryDetails(new Attributes {
                                Attribute_Id = request.AgentInfo.Country
                            }, objTokenResponse.Token).Result;
                            if (countryInfo != null && !string.IsNullOrEmpty(countryInfo.ResortInfo.Voyager_Resort_Id))
                            {
                                request.AgentInfo.CountryName = countryInfo.ResortInfo.ResortName;
                            }
                            else
                            {
                                return(BadRequest(countryInfo.ResponseStatus));
                            }

                            var cityInfo = agentProviders.GetPartnerCityDetails(new Attributes {
                                Attribute_Id = request.AgentInfo.City
                            }, request.AgentInfo.Country, countryInfo.ResortInfo.ResortCode, objTokenResponse.Token).Result;
                            if (cityInfo != null && !string.IsNullOrEmpty(cityInfo.ResortInfo.Voyager_Resort_Id))
                            {
                                request.AgentInfo.CityName = cityInfo.ResortInfo.ResortName;
                            }
                            else
                            {
                                return(BadRequest(cityInfo.ResponseStatus));
                            }

                            request.AgentInfo.Country = countryInfo.ResortInfo.Voyager_Resort_Id;
                            request.AgentInfo.City    = cityInfo.ResortInfo.Voyager_Resort_Id;

                            response = agentProviders.CreateUpdatePartnerAgentDetails(request, objTokenResponse.Token).Result;

                            if (response.ResponseStatus != null && !string.IsNullOrEmpty(response.ResponseStatus.Status) && response.ResponseStatus.Status.ToLower() == "duplicate")
                            {
                                return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status422UnprocessableEntity, response.ResponseStatus));
                            }
                            if (response.ResponseStatus != null && !string.IsNullOrEmpty(response.ResponseStatus.StatusMessage) && response.ResponseStatus.StatusMessage.ToLower() == "companycodeerror")
                            {
                                return(BadRequest(response.ResponseStatus));
                            }
                        }
                        else
                        {
                            return(Unauthorized());
                        }
                    }
                    else
                    {
                        response.ResponseStatus.Status       = "Failure";
                        response.ResponseStatus.ErrorMessage = "AgentInfo details can not be save due to error.";
                        return(BadRequest(response.ResponseStatus));
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = "An error occurs " + ex.Message.ToString();
                return(BadRequest(response.ResponseStatus));
            }
            return(Ok(new { Status = response.ResponseStatus.Status, ErrorMessage = response.ResponseStatus.ErrorMessage, StatusMessage = response.ResponseStatus.StatusMessage, Id = response.CompanyInfo.Company_Id }));
        }
Пример #3
0
        public async Task <IActionResult> IntegrationLogin(IntegrationLoginViewModel model, string returnUrl)
        {
            IntegrationLoginRequest objLoginRequest = new IntegrationLoginRequest();

            objLoginRequest.User      = !string.IsNullOrEmpty(model.User) ? model.User.Replace(' ', '+') : string.Empty; // User secret key Encrypted
            objLoginRequest.Key       = !string.IsNullOrEmpty(model.Key) ? model.Key.Replace(' ', '+') : string.Empty;   //Application Key Encrypted
            objLoginRequest.Source    = model.Source;
            objLoginRequest.Module    = model.Module;
            objLoginRequest.Operation = model.Operation;

            if (string.IsNullOrEmpty(returnUrl))
            {
                DeleteAllCookies();
            }
            else
            {
                return(RedirectToLocal(returnUrl));
            }

            List <ProductAttributeDetails> commonSession = new List <ProductAttributeDetails>();

            if (!string.IsNullOrEmpty(returnUrl) && HttpContext.Session.GetComplexData <List <ProductAttributeDetails> >(SessionName) != null)
            {
                commonSession = HttpContext.Session.GetComplexData <List <ProductAttributeDetails> >(SessionName);
                return(RedirectToLocal(returnUrl));
            }

            IntegrationLoginResponse objTokenResponse = loginProviders.GetIntegrationToken(objLoginRequest).Result;

            if (objTokenResponse.Message == "Success" && objTokenResponse.Token != "")
            {
                Response.Cookies.Append("JWTToken", objTokenResponse.Token, new CookieOptions {
                    Expires = DateTimeOffset.Now.AddMinutes(Convert.ToInt32(1000))
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "JWTToken", Value = objTokenResponse.Token
                });

                UserDetailsRequest objUserDetailsRequest = new UserDetailsRequest();
                objUserDetailsRequest.UserName = objTokenResponse.UserInfo.Email;
                UserDetailsResponse objUserDetailsResponse = loginProviders.GetUserDetails(objUserDetailsRequest, objTokenResponse.Token).Result;

                if (objUserDetailsResponse == null)
                {
                    throw new ApplicationException("UserDetailsResponse is null");
                }

                string EmailId = objTokenResponse.UserInfo.Email;
                int    time    = Convert.ToInt32(objTokenResponse.Expiry);
                SetCookiesForLoginUser(objUserDetailsResponse, EmailId, Convert.ToInt32(objTokenResponse.Expiry));
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "EmailId", Value = EmailId
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "UserName", Value = objUserDetailsResponse.FirstName + " " + objUserDetailsResponse.LastName
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "ContactDisplayMessage", Value = objUserDetailsResponse.ContactDisplayMessage
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CompanyName", Value = objUserDetailsResponse.CompanyName
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "Currency", Value = objUserDetailsResponse.Currency
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "BalanceAmount", Value = objUserDetailsResponse.BalanceAmount
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CreditAmount", Value = objUserDetailsResponse.CreditAmount
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "Photo", Value = objUserDetailsResponse.Photo ?? ""
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "UserRoles", Value = objUserDetailsResponse.UserRoleDetails.Count > 0 ? string.Join(",", objUserDetailsResponse.UserRoleDetails.Select(a => a.RoleName)) : "No Role"
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "VoyagerUser_Id", Value = objUserDetailsResponse.VoyagerUser_Id
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CompanyId", Value = objUserDetailsResponse.CompanyId
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "ContactId", Value = objUserDetailsResponse.ContactId
                });

                HttpContext.Session.SetComplexData(SessionName, commonSession);

                //Set user login date in mUsers
                UserSetReq request = new UserSetReq();
                request.User.VoyagerUser_Id = objUserDetailsResponse.VoyagerUser_Id;
                request.User.LastLoginDate  = DateTime.Now;
                UserSetRes response = loginProviders.UpdateUser(request, objTokenResponse.Token).Result;

                // create claims
                List <Claim> claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, objTokenResponse.UserInfo.Email),
                    new Claim(ClaimTypes.Email, objTokenResponse.UserInfo.Email)
                };

                // create identity
                ClaimsIdentity identity = new ClaimsIdentity(claims, "cookie");

                // create principal
                ClaimsPrincipal principal = new ClaimsPrincipal(identity);

                // sign-in
                await HttpContext.SignInAsync(
                    principal : principal,
                    properties : new AuthenticationProperties
                {
                    ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToInt32(objTokenResponse.Expiry))
                });

                if (returnUrl != null)
                {
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    return(CommonRedirectionBasedOnSource(objLoginRequest, objTokenResponse.Token));
                }
            }
            else
            {
                ViewBag.Unautherized = true;
                return(View("IntegrationError"));
            }
        }