Пример #1
0
        public async Task<IHttpActionResult> GetUserDetails()
        {
            string userId = User.Identity.GetUserId();
            UserResultModel userResultModel = new UserResultModel();
            LeadModel leadModel = new LeadModel();
            ContactModel contactModel = new ContactModel();
            string crmContactId = this.userService.GetContact(userId).CRMId;
            string crmLeadId = string.Empty;

            if (!string.IsNullOrEmpty(crmContactId))
            {
                crmLeadId = this.youfferContactService.GetMappingEntryByContactId(userId).LeadId;
            }

            CountryModel countryDet = this.commonService.GetUserCountryDetails(userId);
            decimal rank = this.crmManagerService.GetUserRank(crmContactId);

            if (!string.IsNullOrEmpty(crmLeadId))
            {
                leadModel = this.crmManagerService.GetLead(crmLeadId);
                userResultModel = this.mapperFactory.GetMapper<LeadModel, UserResultModel>().Map(leadModel);
                userResultModel.Id = userId;
                userResultModel.Rank = rank;
                userResultModel.CountryDetails = countryDet;
                userResultModel.UserRole = Roles.Customer;
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = leadModel.PaypalId,
                    Mode = (PaymentMode)leadModel.PaymentMode
                };

                return this.Ok(userResultModel);
            }
            else
            {
                contactModel = this.crmManagerService.GetContact(userId);
                userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel);
                userResultModel.Id = userId;
                userResultModel.Rank = rank;
                userResultModel.CountryDetails = countryDet;
                userResultModel.UserRole = Roles.Customer;
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = contactModel.PaypalId,
                    Mode = (PaymentMode)contactModel.PaymentMode
                };

                return this.Ok(userResultModel);
            }
        }
Пример #2
0
        public async Task<IHttpActionResult> GetMExternalLogin(RegisterExternalBindingModel model)
        {
            try
            {
                try
                {
                    this.LoggerService.LogException("MExternalLogin Request -json- " + JsonConvert.SerializeObject(model));
                }
                catch (Exception ex1)
                {
                }

                var verifiedAccessToken = await this.VerifyExternalAccessToken(model.Provider, model.ExternalAccessToken);
                if (verifiedAccessToken == null)
                {
                    return this.BadRequest("Invalid Provider or External Access Token");
                }

                var user = await this.authRepository.FindAsync(new UserLoginInfo(model.Provider, verifiedAccessToken.UserId));

                model.IsFromMobile = true;
                model.UserRole = (Roles)model.Role;
                model.OSType = (OSType)model.OS;

                ////string ipAddress = string.IsNullOrEmpty(model.IPAddress) ? HttpContext.Current.Request.UserHostAddress : model.IPAddress;
                ////this.LoggerService.LogException("IP Address from Request - " + ipAddress);
                ////CityDto cityData = this.ip2LocationService.GetCityData(ipAddress);
                ////model.Country = cityData.CountryInfo.CountryName;
                ////model.State = cityData.MostSpecificSubDivisionName == null ? string.Empty : cityData.MostSpecificSubDivisionName;
                ////model.Latitude = cityData.Latitude;
                ////model.Longitude = cityData.Longitude;

                bool hasRegistered = user != null;

                if (!hasRegistered)
                {
                    return await this.RegisterExternal(model);
                }

                AccessTokenModel accessTokenResponse = this.GenerateLocalAccessTokenResponse(user);
                CountryModel countryDet = this.commonService.GetUserCountryDetails(user.Id);

                if (model.UserRole == Roles.Customer)
                {
                    string crmContactId = this.userService.GetContact(user.Id).CRMId;
                    decimal rank = this.crmManagerService.GetUserRank(crmContactId);
                    string crmLeadId = string.Empty;
                    if (!string.IsNullOrEmpty(crmContactId))
                    {
                        crmLeadId = this.youfferContactService.GetMappingEntryByContactId(user.Id).LeadId;
                    }

                    ContactModel contactModel = new ContactModel();
                    contactModel = this.crmManagerService.GetContact(user.Id);
                    contactModel.IsOnline = true;
                    if (!string.IsNullOrWhiteSpace(model.GCMId))
                    {
                        contactModel.GCMId = model.GCMId;
                    }

                    if (!string.IsNullOrWhiteSpace(model.UDId))
                    {
                        contactModel.UDId = model.UDId;
                    }

                    contactModel = this.crmManagerService.UpdateContact(user.Id, contactModel);

                    LeadModel leadModel = new LeadModel();
                    UserResultModel userResultModel = new UserResultModel();

                    if (!string.IsNullOrEmpty(crmLeadId))
                    {
                        leadModel = this.crmManagerService.GetLead(crmLeadId);

                        userResultModel = this.mapperFactory.GetMapper<LeadModel, UserResultModel>().Map(leadModel) ?? new UserResultModel();
                        userResultModel.Id = user.Id;
                        userResultModel.ExternalAccessToken = accessTokenResponse;
                        userResultModel.Rank = rank;
                        userResultModel.CountryDetails = countryDet;
                        userResultModel.UserRole = Roles.Customer;
                        userResultModel.PaymentDetails = new PaymentModelDto()
                        {
                            PayPalId = leadModel.PaypalId,
                            Mode = (PaymentMode)leadModel.PaymentMode
                        };
                    }
                    else
                    {
                        userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel) ?? new UserResultModel();
                        userResultModel.Id = user.Id;
                        userResultModel.ExternalAccessToken = accessTokenResponse;
                        userResultModel.CountryDetails = countryDet;
                        userResultModel.UserRole = Roles.Customer;
                        userResultModel.PaymentDetails = new PaymentModelDto()
                        {
                            PayPalId = contactModel.PaypalId,
                            Mode = (PaymentMode)contactModel.PaymentMode
                        };
                    }

                    return this.Ok(userResultModel);
                }
                else
                {
                    OrgResultModel orgResultModel = new OrgResultModel();
                    OrganisationModel orgModel = new OrganisationModel();

                    orgModel = this.crmManagerService.GetOrganisation(user.Id);
                    orgResultModel = this.mapperFactory.GetMapper<OrganisationModel, OrgResultModel>().Map(orgModel) ?? new OrgResultModel();
                    orgResultModel.Id = user.Id;
                    orgResultModel.ExternalAccessToken = accessTokenResponse.ToString();
                    orgResultModel.CountryDetails = countryDet;
                    orgResultModel.UserRole = Roles.Company;
                    orgResultModel.PaymentDetails = string.Empty;

                    return this.Ok(orgResultModel);
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("GetMExternalLogin : " + ex.Message);
                return this.BadRequest(ex.Message);
            }
        }