Ejemplo n.º 1
0
        public async Task<IHttpActionResult> GetUnReviewedClientsCnt()
        {
            string companyId = User.Identity.GetUserId();
            List<UserResultModel> lstUserResultModel = new List<UserResultModel>();
            UnreviewedClientsCountDto unreviewedClientsCountDto = new UnreviewedClientsCountDto();
            List<VTigerPotential> lst = this.crmManagerService.GetUnReviewdClients(companyId, 1, int.MaxValue);
            int count = 0;

            foreach (var item in lst)
            {
                UserResultModel userResultModel = new UserResultModel();
                string userId = this.userService.GetContactByCrmId(item.contact_id).Id;

                if (userId != null)
                {
                    count++;
                }
            }

            unreviewedClientsCountDto.Count = count;
            return this.Ok(unreviewedClientsCountDto);
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> GetUserDetails(string userId)
        {
            UserResultModel userResultModel = new UserResultModel();
            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);

            var reviews = this.crmManagerService.GetUserReviews(crmContactId);
            List<UserReviewsDto> lstReviews = this.mapperFactory.GetMapper<List<CRMUserReview>, List<UserReviewsDto>>().Map(reviews);

            if (!string.IsNullOrEmpty(crmLeadId))
            {
                LeadModel leadModel = this.crmManagerService.GetLead(crmLeadId);
                userResultModel = this.mapperFactory.GetMapper<LeadModel, UserResultModel>().Map(leadModel);
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = leadModel.PaypalId,
                    Mode = (PaymentMode)leadModel.PaymentMode
                };
            }
            else
            {
                ContactModel contactModel = this.crmManagerService.GetContact(userId);
                userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel);
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = contactModel.PaypalId,
                    Mode = (PaymentMode)contactModel.PaymentMode
                };
            }

            userResultModel.Id = userId;
            userResultModel.Rank = rank;
            userResultModel.CountryDetails = countryDet;
            userResultModel.UserRole = Roles.Customer;
            userResultModel.UserReviews = lstReviews;

            return this.Ok(userResultModel);
        }
Ejemplo n.º 3
0
        public async Task<IHttpActionResult> GetUnReviewedClients(int lastpageId = 0, int fetchCount = 0)
        {
            if (fetchCount == 0)
            {
                fetchCount = AppSettings.Get<int>(ConfigConstants.DashboardLeadsDefaultCount);
            }

            string companyId = User.Identity.GetUserId();
            List<UserResultModel> lstUserResultModel = new List<UserResultModel>();

            List<VTigerPotential> lst = this.crmManagerService.GetUnReviewdClients(companyId, lastpageId, fetchCount);

            foreach (var item in lst)
            {
                UserResultModel userResultModel = new UserResultModel();
                string userId = this.userService.GetContactByCrmId(item.contact_id).Id;

                if (userId != null)
                {
                    ContactModel contactModel = this.crmManagerService.GetContact(userId);
                    CountryModel countryDet = this.commonService.GetUserCountryDetailsFromName(contactModel.MailingCountry);
                    decimal rank = this.crmManagerService.GetUserRank(item.contact_id);

                    userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel);
                    userResultModel.Id = userId;
                    userResultModel.Rank = rank;
                    userResultModel.SubInterest = item.cf_853.Split(',');
                    userResultModel.CountryDetails = countryDet;
                    userResultModel.UserRole = Roles.Customer;
                    userResultModel.CreatedOn = item.createdtime;
                    userResultModel.CanCall = item.cf_843;
                    userResultModel.PaymentDetails = new PaymentModelDto()
                        {
                            PayPalId = contactModel.PaypalId,
                            Mode = contactModel.PaymentMode
                        };
                }

                lstUserResultModel.Add(userResultModel);
            }

            return this.Ok(lstUserResultModel);
        }
Ejemplo n.º 4
0
        public async Task<IHttpActionResult> GetUnReviewedClients1(int lastpageId = 0, int fetchCount = 0)
        {
            if (fetchCount == 0)
            {
                fetchCount = AppSettings.Get<int>(ConfigConstants.DashboardLeadsDefaultCount);
            }

            string companyId = User.Identity.GetUserId();
            List<UserResultModel> lstUserResultModel = new List<UserResultModel>();

            List<VtigerPotentialData> lst = this.crmManagerService.GetUnReviewdClients1(companyId, lastpageId, fetchCount);

            foreach (var item in lst)
            {
                UserResultModel userResultModel = new UserResultModel();
                string userId = this.userService.GetContactByCrmId(AppSettings.Get<string>(ConfigConstants.ContactId) + item.contactid).Id;

                if (userId != null)
                {
                    CountryModel countryDet = this.commonService.GetUserCountryDetailsFromName(item.mailingcountry);
                    userResultModel = this.mapperFactory.GetMapper<VtigerPotentialData, UserResultModel>().Map(item);
                    userResultModel.Id = userId;
                    userResultModel.Description = userResultModel.Description ?? string.Empty;
                    userResultModel.SubInterest = item.cf_853.Split(',');
                    userResultModel.CountryDetails = countryDet;
                    userResultModel.UserRole = Roles.Customer;
                    userResultModel.PaymentDetails = new PaymentModelDto
                    {
                        PayPalId = item.cf_847,
                        Mode = string.IsNullOrWhiteSpace(item.cf_847) ? PaymentMode.Undefined : PaymentMode.Paypal
                    };
                }

                lstUserResultModel.Add(userResultModel);
            }

            return this.Ok(lstUserResultModel);
        }
Ejemplo n.º 5
0
        public async Task<IHttpActionResult> SearchClientForReviewPage(string searchText, int lastpageId = 0, int fetchCount = 0)
        {
            if (fetchCount == 0)
            {
                fetchCount = AppSettings.Get<int>(ConfigConstants.DashboardLeadsDefaultCount);
            }

            if (searchText != null)
            {
                searchText = HttpUtility.UrlDecode(searchText);
            }

            List<UserResultModel> lstUserResultModel = new List<UserResultModel>();
            string companyId = User.Identity.GetUserId();
            List<VTigerPotential> lst = this.crmManagerService.SearchClientForReviewPage(searchText, companyId, lastpageId, fetchCount);

            foreach (var item in lst)
            {
                string userId = this.userService.GetContactByCrmId(item.contact_id).Id;

                if (!string.IsNullOrWhiteSpace(userId))
                {
                    ContactModel contactModel = this.crmManagerService.GetContact(userId);
                    bool isContionTrue = false;
                    if (!string.IsNullOrWhiteSpace(searchText))
                    {
                        if (!string.IsNullOrWhiteSpace(contactModel.FirstName) && contactModel.FirstName.ToLowerString().Contains(searchText.ToLower()))
                        {
                            isContionTrue = true;
                        }
                    }
                    else
                    {
                        isContionTrue = true;
                    }

                    if (isContionTrue)
                    {
                        CountryModel countryDet = this.commonService.GetUserCountryDetailsFromName(contactModel.MailingCountry);
                        decimal rank = this.crmManagerService.GetUserRank(item.contact_id);

                        UserResultModel result = new UserResultModel();
                        result = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel);
                        result.Id = userId;
                        result.CreatedOn = item.createdtime;
                        result.SubInterest = item.cf_853.Split(',');
                        result.CountryDetails = countryDet;
                        result.Rank = rank;
                        result.CanCall = item.cf_843;
                        lstUserResultModel.Add(result);
                    }
                }
            }

            return this.Ok(lstUserResultModel);
        }
Ejemplo n.º 6
0
        public async Task<IHttpActionResult> UpdateUserDetails(ContactModel contactModel)
        {
            string userId = User.Identity.GetUserId();
            var contact = this.crmManagerService.GetContact(userId);

            if (!string.IsNullOrEmpty(contactModel.FirstName))
            {
                contact.FirstName = contactModel.FirstName;
                ApplicationUserDto user = this.userService.GetContact(userId);
                user.Name = contactModel.FirstName;
                this.userService.UpdateUser(user);
            }

            contact.GCMId = string.IsNullOrEmpty(contactModel.GCMId) ? contact.GCMId : contactModel.GCMId;
            contact.UDId = string.IsNullOrEmpty(contactModel.UDId) ? contact.UDId : contactModel.UDId;
            contact.LastName = string.IsNullOrEmpty(contactModel.LastName) ? contact.LastName : contactModel.LastName;
            contact.SubInterest = contactModel.SubInterest == null ? contact.SubInterest : contactModel.SubInterest;
            contact.IsAvailable = contactModel.IsAvailable == null ? contact.IsAvailable : contactModel.IsAvailable;
            contact.IsOnline = contactModel.IsOnline == null ? contact.IsOnline : contactModel.IsOnline;
            contact.Availability = (int)contactModel.Availability == 0 ? contact.Availability : contactModel.Availability;
            contact.AvailableFrom = string.IsNullOrEmpty(contactModel.AvailableFrom) ? contact.AvailableFrom : contactModel.AvailableFrom;
            contact.AvailableTo = string.IsNullOrEmpty(contactModel.AvailableTo) ? contact.AvailableTo : contactModel.AvailableTo;
            ////contact.CountryCode = string.IsNullOrEmpty(contactModel.CountryCode) ? contact.CountryCode : contactModel.CountryCode;
            ////contact.Phone = string.IsNullOrEmpty(contactModel.Phone) ? contact.Phone : contactModel.Phone;
            if (string.IsNullOrEmpty(contactModel.Phone))
            {
                contact.Phone = contact.Phone;
            }
            else
            {
                contact.Phone = contactModel.Phone;
                if (contactModel.CountryCode == "US" || contactModel.CountryCode == "1" || contact.CountryCode == "US")
                {
                    this.LoggerService.LogException("Entered AreaCode saving code - " + contactModel.Phone);
                    string areaCode = string.Empty;

                    if (contact.Phone.Split('-').Length > 0)
                    {
                        areaCode = contact.Phone.Split('-')[0].ToString();
                        this.LoggerService.LogException("AreaCode saved with new format - " + areaCode);
                    }
                    else
                    {
                        if (contact.Phone.StartsWith("+"))
                        {
                            areaCode = contact.Phone.Substring(2, 3);
                        }
                        else
                        {
                            areaCode = contact.Phone.Substring(0, 3);
                        }

                        this.LoggerService.LogException("AreaCode saved with old format - " + areaCode);
                    }

                    contact.MailingState = this.commonService.GetStateFromAreaCode(areaCode).StateName;
                    this.LoggerService.LogException("MailingState - " + contact.MailingState + " for - " + contact.FirstName);
                }
            }

            contact.Description = string.IsNullOrEmpty(contactModel.Description) ? contact.Description : contactModel.Description;
            contact.MailingCountry = contactModel.MailingCountry == null ? contact.MailingCountry : contactModel.MailingCountry;
            contact.Latitude = contactModel.Latitude <= 0 ? contact.Latitude : contactModel.Latitude;
            contact.Longitude = contactModel.Longitude <= 0 ? contact.Longitude : contactModel.Longitude;
            contact.CountryCode = string.IsNullOrWhiteSpace(contactModel.CountryCode) ? contact.CountryCode : contactModel.CountryCode;

            if (!string.IsNullOrWhiteSpace(contactModel.PaypalId))
            {
                contact.PaypalId = contactModel.PaypalId;
            }

            contactModel = this.crmManagerService.UpdateContact(userId, contact);

            if (contactModel == null)
            {
                return this.BadRequest();
            }

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

            UserResultModel userResultModel = new UserResultModel();
            userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel);
            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);
        }
Ejemplo n.º 7
0
        public async Task<IHttpActionResult> CreateRequest(G2SModel g2SModel)
        {
            UserResultModel userResultModel = new UserResultModel();
            string crmContactId = this.userService.GetContact(g2SModel.ClientId).CRMId;
            string crmLeadId = string.Empty;

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

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

            var reviews = this.crmManagerService.GetUserReviews(crmContactId);
            List<UserReviewsDto> lstReviews = this.mapperFactory.GetMapper<List<CRMUserReview>, List<UserReviewsDto>>().Map(reviews);

            if (!string.IsNullOrEmpty(crmLeadId))
            {
                LeadModel leadModel = this.crmManagerService.GetLead(crmLeadId);
                userResultModel = this.mapperFactory.GetMapper<LeadModel, UserResultModel>().Map(leadModel);
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = leadModel.PaypalId,
                    Mode = (PaymentMode)leadModel.PaymentMode
                };
            }
            else
            {
                ContactModel contactModel = this.crmManagerService.GetContact(g2SModel.ClientId);
                userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(contactModel);
                userResultModel.PaymentDetails = new PaymentModelDto()
                {
                    PayPalId = contactModel.PaypalId,
                    Mode = (PaymentMode)contactModel.PaymentMode
                };
            }

            userResultModel.Id = g2SModel.ClientId;
            userResultModel.Rank = rank;
            userResultModel.CountryDetails = countryDet;
            userResultModel.UserRole = Roles.Customer;
            userResultModel.UserReviews = lstReviews;

            ProductModel productModel = new ProductModel()
            {
                Id = userResultModel.Id,
                Title = userResultModel.FirstName,
                Price = AppSettings.Get<decimal>("interestPrice")
            };
            g2SModel.Product = productModel;
            g2SModel.ProcessingFee = (g2SModel.Product.Price * AppSettings.Get<decimal>("processingFeePercent")) / 100;
            g2SModel.CompanyId = User.Identity.GetUserId();
            string merchantKey = AppSettings.Get<string>("secret_key");
            string pppUrl = AppSettings.Get<string>("live_pppURL");
            ////string pppUrl = AppSettings.Get<string>("test_pppURL");
            try
            {
                g2SModel.InvoiceId = this.CreateInvoice(g2SModel).ToString();
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("PaymentController > CreateRequest(while creating invoice): " + ex.StackTrace);
            }

            Dictionary<string, string> parameters = this.ConstructParametersMap(this.encoding, g2SModel);
            string checksum = this.CalculateChecksum(parameters, merchantKey, this.encoding);
            parameters.Add("checksum", checksum);
            string encoded_params = this.EncodeParameters(parameters, this.encoding);
            try
            {
                G2SRequestModel g2SRequestModel = this.FillG2SRequest(parameters, g2SModel);
                this.paymentService.InsertG2SRequest(g2SRequestModel);
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("PaymentController > G2SSuccess(while filling or inserting request): " + ex.StackTrace);
            }

            return this.Ok(pppUrl + encoded_params);
        }
Ejemplo n.º 8
0
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            ExternalLoginResultModel externalLoginResultModel = new ExternalLoginResultModel();
            try
            {
                model.Country = string.IsNullOrWhiteSpace(model.Country) ? string.Empty : HttpUtility.UrlDecode(model.Country);
                ContactModel userModel = new ContactModel();
                OrganisationModel orgModel = new OrganisationModel();

                if (!this.ModelState.IsValid)
                {
                    return this.BadRequest(this.ModelState);
                }

                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));

                bool hasRegistered = user != null;

                if (!hasRegistered)
                {
                    userModel = this.GetExternalUserDetails(model.Provider, model.ExternalAccessToken);
                    if (string.IsNullOrEmpty(userModel.Email))
                    {
                        userModel.Email = model.Email;
                    }

                    userModel.GCMId = model.GCMId;
                    userModel.UDId = model.UDId;
                    userModel.OSType = model.OSType;
                    userModel.MailingCountry = model.Country;
                    userModel.MailingState = model.State;
                    userModel.CountryCode = model.CountryCode;
                    userModel.Timezone = model.Timezone;
                    userModel.Latitude = model.Latitude;
                    userModel.Longitude = model.Longitude;
                    userModel.IsAvailable = true;
                    userModel.Availability = Availability.AllDays;
                    userModel.AvailableFrom = "08:00:00";
                    userModel.AvailableTo = "20:00:00";
                    userModel.IsOnline = true;
                    userModel.IsActive = true;
                    string userName = userModel.Email;
                    if (string.IsNullOrWhiteSpace(userModel.Email))
                    {
                        userName = Guid.NewGuid().ToString();
                    }

                    user = new ApplicationUserDto
                    {
                        UserName = userName,
                        Email = userModel.Email,
                        Name = userModel.FirstName,
                        AccountType = (short)model.UserRole
                    };

                    if (model.Provider == "Facebook")
                    {
                        user.FacebookId = verifiedAccessToken.UserId;
                        user.FBAccessToken = model.ExternalAccessToken;
                    }
                    else
                    {
                        user.GoogleId = verifiedAccessToken.UserId;
                        user.GoogleAccessToken = model.ExternalAccessToken;
                    }

                    IdentityResult result = await this.authRepository.CreateAsync(user, model.UserRole.ToString());
                    if (!result.Succeeded)
                    {
                        string errorMessage = result.Errors.Any() ? result.Errors.First() : string.Empty;
                        return this.BadRequest(errorMessage);
                    }

                    var info = new ExternalLoginInfo
                    {
                        DefaultUserName = model.UserName,
                        Login = new UserLoginInfo(model.Provider, verifiedAccessToken.UserId)
                    };

                    result = await this.authRepository.AddLoginAsync(user.Id, info.Login);
                    if (!result.Succeeded)
                    {
                        return this.GetErrorResult(result);
                    }

                    userModel.ImageURL = ImageHelper.SaveImageFromUrl(userModel.ImageURL, user.Id);

                    if (model.UserRole == Roles.Company)
                    {
                        orgModel.AccountName = userModel.FirstName;
                        orgModel.Email1 = userModel.Email;
                        orgModel.FacebookURL = userModel.FBUrl;
                        orgModel.GooglePlusURL = userModel.GooglePlusURL;
                        orgModel.ImageURL = userModel.ImageURL;
                        orgModel = this.crmManagerService.AddOrganisation(orgModel, user);
                    }
                    else
                    {
                        userModel = this.crmManagerService.AddContact(userModel, user);
                    }
                }

                if (model.IsFromMobile)
                {
                    var accessTokenResponse = this.GenerateLocalAccessTokenResponse(user);
                    UserResultModel userResultModel = new UserResultModel();
                    OrgResultModel orgResultModel = new OrgResultModel();

                    CountryModel countryDet = this.commonService.GetUserCountryDetailsFromName(userModel.MailingCountry);

                    if (model.UserRole == Roles.Customer)
                    {
                        userResultModel = this.mapperFactory.GetMapper<ContactModel, UserResultModel>().Map(userModel);
                        userResultModel.ExternalAccessToken = accessTokenResponse;
                        userResultModel.Rank = 0.0M;
                        userResultModel.CountryDetails = countryDet;
                        userResultModel.UserRole = Roles.Customer;
                        userResultModel.IsActive = userModel.IsActive;
                        userResultModel.PaymentDetails = new PaymentModelDto()
                        {
                            PayPalId = userModel.PaypalId,
                            Mode = (PaymentMode)userModel.PaymentMode
                        };

                        MessagesDto message = new MessagesDto();
                        message.ModifiedBy = message.FromUser = message.CreatedBy = "YoufferAdmin";
                        message.IsDeleted = false;
                        message.CompanyId = AppSettings.Get<string>(ConfigConstants.SuperUserId);
                        message.UserId = message.ToUser = user.Id;
                        message.Name = "Youffer Admin";
                        message.MediaId = 0;

                        MessageTemplatesDto msgTemplate = this.commonService.GetMessageTemplate(MessageTemplateType.WelcomeMsg);
                        message.Message = msgTemplate.TemplateText;
                        this.youfferMessageService.CreateMessage(message);
                        int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, false);

                        if (!string.IsNullOrEmpty(userResultModel.GCMId))
                        {
                            this.pushMessageService.SendMessageNotificationToAndroid(userResultModel.GCMId, message.Id.ToString(), message.Message, "Youffer", Notification.companymsg.ToString());
                        }

                        if (!string.IsNullOrEmpty(userResultModel.UDId))
                        {
                            this.pushMessageService.SendMessageNotificationToiOS(userResultModel.UDId, message.Id.ToString(), message.Message, "Youffer", unreadMsgCount, Notification.usermsg.ToString());
                        }

                        return this.Ok(userResultModel);
                    }
                    else
                    {
                        orgResultModel = this.mapperFactory.GetMapper<OrganisationModel, OrgResultModel>().Map(orgModel);
                        orgResultModel.ExternalAccessToken = accessTokenResponse.ToString();
                        orgResultModel.CountryDetails = countryDet;
                        orgResultModel.UserRole = Roles.Company;
                        orgResultModel.PaymentDetails = string.Empty;

                        return this.Ok(orgResultModel);
                    }
                }

                var redirectUri = string.Empty;
                var redirectUriValidationResult = this.ValidateClientAndRedirectUri(ref redirectUri);
                if (!string.IsNullOrEmpty(redirectUri))
                {
                    redirectUri = string.Format(
                                                  "{0}?external_access_token={1}&provider={2}&haslocalaccount={3}&external_user_name={4}",
                                                  redirectUri,
                                                  model.ExternalAccessToken,
                                                  model.Provider,
                                                  hasRegistered.ToString(),
                                                  model.UserName);
                    return this.Redirect(redirectUri);
                }

                externalLoginResultModel.ExternalAccessToken = model.ExternalAccessToken;
                externalLoginResultModel.Provider = model.Provider;
                externalLoginResultModel.HasLocalAccount = hasRegistered;
                externalLoginResultModel.ExternalUserName = model.UserName;
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("RegisterExternal : " + ex.Message);
            }

            return this.Ok(externalLoginResultModel);
        }
Ejemplo n.º 9
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);
            }
        }