示例#1
0
        /// <summary>
        /// Creates the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>The MessagesDto object.</returns>
        public MessagesDto CreateMessage(MessagesDto message)
        {
            try
            {
                MessageThreadDto messageThread = this.GetMessageThread(message.FromUser, message.ToUser);
                if (messageThread == null || messageThread.Id < 1)
                {
                    messageThread = new MessageThreadDto { FromUser = message.FromUser, ToUser = message.ToUser, CreatedBy = message.FromUser, ModifiedBy = message.FromUser };
                    messageThread = this.CreateMessageThread(messageThread);
                }

                if (messageThread.IsDeleted || messageThread.IsDeletedByUser || messageThread.IsDeletedByCompany)
                {
                    messageThread.IsDeleted = messageThread.IsDeletedByUser = messageThread.IsDeletedByCompany = false;
                    messageThread.ModifiedOn = DateTime.UtcNow;
                    MessageThread thread = this.mapperFactory.GetMapper<MessageThreadDto, MessageThread>().Map(messageThread);
                    this.messageThreadRepository.Update(thread);
                    this.messageThreadRepository.Commit();
                }

                message.ThreadId = messageThread.Id;
                Messages msg = this.mapperFactory.GetMapper<MessagesDto, Messages>().Map(message);
                this.messageRepository.Insert(msg);
                this.messageRepository.Commit();

                message = this.mapperFactory.GetMapper<Messages, MessagesDto>().Map(msg);
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("CreateMessage - " + ex.Message);
            }

            return message;
        }
示例#2
0
        public async Task<IHttpActionResult> GetAllCompanyMessages(int lastpageId = 0, int fetchCount = 0, string sortBy = "", string direction = "asc")
        {
            if (sortBy == null)
            {
                sortBy = string.Empty;
            }

            if (direction == null)
            {
                direction = "asc";
            }

            if (fetchCount == 0 || fetchCount == null)
            {
                fetchCount = AppSettings.Get<int>(ConfigConstants.MessageDefaultCount);
            }

            string companyId = User.Identity.GetUserId();
            ApplicationUserDto companyDet = this.youfferContactService.GetOrgCRMId(companyId);
            string companyName = companyDet.Name;
            string orgCRMId = companyDet.CRMId;

            List<MessagesDto> lstMessages = this.youfferMessageService.GetAllCompanyMessages(companyId, lastpageId, fetchCount, sortBy, direction);

            if (lastpageId <= 1)
            {
                CRMContactUs contactUs = this.crmManagerService.ReadContactUsMessage(orgCRMId);

                if (contactUs != null)
                {
                    try
                    {
                        MessageThreadDto msgThread = this.youfferMessageService.GetMessageThread(companyId, "YoufferAdmin");
                        if (msgThread != null)
                        {
                            MessagesDto msg = new MessagesDto()
                            {
                                Id = Convert.ToInt32(contactUs.Id.Split('x')[1]),
                                IsRead = true,
                                CreatedOn = contactUs.CreatedOn,
                                ModifiedOn = contactUs.ModifiedOn,
                                FromUser = contactUs.IsIncomingMessage ? companyId : "Youffer Admin",
                                CreatedBy = contactUs.IsIncomingMessage ? companyId : "Youffer Admin",
                                ModifiedBy = contactUs.IsIncomingMessage ? companyId : "Youffer Admin",
                                CompanyId = companyId,
                                ToUser = contactUs.IsIncomingMessage ? "Youffer Admin" : companyId,
                                Message = contactUs.Description,
                                Subject = contactUs.Subject,
                                DeptId = (ContactUsDept)Enum.Parse(typeof(ContactUsDept), contactUs.Department),
                                MediaId = 0,
                                Name = "Youffer Admin",
                                UserId = AppSettings.Get<string>(ConfigConstants.SuperUserId),
                                ThreadId = msgThread.Id
                            };

                            lstMessages.Add(msg);
                        }

                        lstMessages = lstMessages.Distinct().OrderByDescending(x => x.CreatedOn).GroupBy(x => x.ThreadId).Select(grp => grp.First()).ToList();
                    }
                    catch (Exception ex)
                    {
                        var a = ex.Message;
                    }
                }
            }

            return this.Ok(lstMessages);
        }
示例#3
0
        public async Task<IHttpActionResult> GetMessages(string userId, int lastpageId = 0, int fetchCount = 0, string sortBy = "", string direction = "asc")
        {
            if (sortBy == null)
            {
                sortBy = string.Empty;
            }

            if (direction == null)
            {
                direction = "asc";
            }

            if (fetchCount == 0 || fetchCount == null)
            {
                fetchCount = AppSettings.Get<int>(ConfigConstants.MessageDefaultCount);
            }

            List<MessagesDto> lstMessages = new List<MessagesDto>();
            string companyId = User.Identity.GetUserId();

            ApplicationUserDto companyDet = this.youfferContactService.GetOrgCRMId(companyId);
            string companyName = companyDet.Name;
            string orgCRMId = companyDet.CRMId;

            MessageThreadDto msgThreadDto = this.youfferMessageService.GetMessageThread(companyId, userId);
            if (msgThreadDto != null && msgThreadDto.Id > 0)
            {
                lstMessages = this.youfferMessageService.GetAllMessages(companyId, msgThreadDto.Id, lastpageId, fetchCount, sortBy, direction);
            }

            List<CRMContactUs> contactUsMsg = this.crmManagerService.ReadAllContactUsMessage(orgCRMId, lastpageId, fetchCount, sortBy, direction);
            foreach (var contactUs in contactUsMsg)
            {
                MessagesDto msg = new MessagesDto()
                {
                    Id = Convert.ToInt32(contactUs.Id.Split('x')[1]),
                    IsRead = true,
                    CreatedOn = contactUs.CreatedOn,
                    ModifiedOn = contactUs.ModifiedOn,
                    FromUser = contactUs.IsIncomingMessage ? companyId : "Youffer Admin",
                    CreatedBy = contactUs.IsIncomingMessage ? companyId : "Youffer Admin",
                    ModifiedBy = contactUs.IsIncomingMessage ? companyId : "Youffer Admin",
                    CompanyId = companyId,
                    ToUser = contactUs.IsIncomingMessage ? "Youffer Admin" : companyId,
                    Message = contactUs.Description,
                    Subject = contactUs.Subject,
                    DeptId = (ContactUsDept)Enum.Parse(typeof(ContactUsDept), contactUs.Department),
                    MediaId = 0,
                    Name = "Youffer Admin",
                    UserId = AppSettings.Get<string>(ConfigConstants.SuperUserId),
                    ThreadId = msgThreadDto.Id
                };

                lstMessages.Add(msg);
            }

            if (direction == "asc")
            {
                lstMessages = lstMessages.OrderBy(x => x.CreatedOn).ToList();
            }
            else
            {
                lstMessages = lstMessages.OrderByDescending(x => x.CreatedOn).ToList();
            }

            return this.Ok(lstMessages);
        }
示例#4
0
        public async Task<IHttpActionResult> CreateMessage(MessagesDto message)
        {
            message.ModifiedBy = message.FromUser = message.CreatedBy = User.Identity.GetUserId();
            message.IsDeleted = false;
            message.IsReadByCompany = true;
            message.CompanyId = message.FromUser;
            message.UserId = message.ToUser;

            message = this.youfferMessageService.CreateMessage(message);
            int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, true);

            ContactModel contact = this.crmManagerService.GetContact(message.ToUser);
            OrganisationModel fromUser = this.crmManagerService.GetOrganisation(message.FromUser);
            if (!string.IsNullOrEmpty(contact.GCMId))
            {
                this.pushMessageService.SendMessageNotificationToAndroid(contact.GCMId, message.Id.ToString(), message.Message, fromUser.AccountName, Notification.companymsg.ToString());
            }

            if (!string.IsNullOrEmpty(contact.UDId))
            {
                this.pushMessageService.SendMessageNotificationToiOS(contact.UDId, message.Id.ToString(), message.Message, fromUser.AccountName, unreadMsgCount, Notification.companymsg.ToString());
            }

            return this.Ok(message);
        }
示例#5
0
        /// <summary>
        /// Updates the credit balance.
        /// </summary>
        private void UpdateCreditBalance()
        {
            try
            {
                using (MySqlContext dbContext = new MySqlContext())
                {
                    IRepository<vtiger_contactdetails> tmp = new Repository<vtiger_contactdetails>(dbContext);
                    var lst = tmp.SqlQuery<SendUpdateCreditBalanceMessageDto>("CALL SendUpdateCreditBalanceMsgAndNotification();").ToList();

                    foreach (var item in lst)
                    {
                        string orgId = string.Empty;
                        string crmUserId;

                        crmUserId = AppSettings.Get<string>(ConfigConstants.OrganisationId) + item.OrgId;
                        var user = this.userService.GetContactByCrmId(crmUserId);
                        if (user != null && !string.IsNullOrWhiteSpace(user.UserName))
                        {
                            orgId = user.Id;
                        }

                        ////Update Organisation's credit balance
                        OrganisationModel org = this.crmManagerService.GetOrganisation(orgId);
                        org.CreditBalance += item.CreditBalance;
                        this.crmManagerService.UpdateOrganisation(orgId, org);

                        string currency = org.BillCountry.ToLower() == "india" ? "₹" : "$";
                        string amount = currency + item.CreditBalance.ToString("#");

                        ////Send email to the organisation
                        this.authRepository.SendCreditBalanceEmail(orgId, org.AccountName, amount);

                        ////Send message and notification to organisation
                        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 = orgId;
                        message.Name = "Youffer Admin";
                        message.MediaId = 0;

                        MessageTemplatesDto msgTemplate = this.commonService.GetMessageTemplate(MessageTemplateType.UpdateCreditBalanceMsg);
                        msgTemplate.TemplateText = msgTemplate.TemplateText.Replace("{{Amount}}", amount);
                        message.Message = msgTemplate.TemplateText;
                        message = this.youfferMessageService.CreateMessage(message);

                        ////Notifications
                        SignalRHub hub = new SignalRHub();
                        UserBalanceModelDto balance = new UserBalanceModelDto { CashBalance = org.CashBalance, CreditBalance = org.CreditBalance };
                        hub.SendMessage(message.UserId, message);
                        hub.SendCreditUpdateMessage(message.UserId, balance);

                        string gcmId = item.GCMId;
                        string udId = item.UDId;

                        if (!string.IsNullOrEmpty(gcmId))
                        {
                            this.pushMessageService.SendMessageNotificationToAndroid(gcmId, message.Id.ToString(), message.Message, "Youffer", Notification.usermsg.ToString());
                            this.pushMessageService.SendCreditNotificationToAndroid(gcmId, message.Id.ToString(), amount, "Youffer", Notification.updatecreditbal.ToString());
                        }

                        if (!string.IsNullOrEmpty(udId))
                        {
                            int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, false);
                            this.pushMessageService.SendMessageNotificationToiOS(udId, message.Id.ToString(), message.Message, "Youffer", unreadMsgCount, Notification.usermsg.ToString());
                            this.pushMessageService.SendCreditNotificationToiOS(udId, message.Id.ToString(), amount, "Youffer", unreadMsgCount, Notification.updatecreditbal.ToString());
                        }

                        var res = tmp.SqlQuery<int>("CALL UpdateCreditBalanceStatus({0});", item.Id).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                this.loggerservice.LogException("UpdateCreditBalance:- " + ex.Message);
            }
        }
示例#6
0
        /// <summary>
        /// Sends the enter needs message and notification.
        /// </summary>
        private void SendEnterNeedsMessageAndNotification()
        {
            try
            {
                using (MySqlContext dbContext = new MySqlContext())
                {
                    IRepository<vtiger_contactdetails> tmp = new Repository<vtiger_contactdetails>(dbContext);
                    var lst = tmp.SqlQuery<SendEnterPhoneAndNeedsMessageDto>("CALL SendEnterNeedsMessageAndNotification();").ToList();

                    foreach (var item in lst)
                    {
                        string userId = string.Empty;
                        string crmUserId;

                        crmUserId = AppSettings.Get<string>(ConfigConstants.ContactId) + item.contactId;
                        var user = this.userService.GetContactByCrmId(crmUserId);
                        if (user != null && !string.IsNullOrWhiteSpace(user.UserName))
                        {
                            userId = user.Id;
                        }

                        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 = userId;
                        message.Name = "Youffer Admin";
                        message.MediaId = 0;

                        MessageTemplatesDto msgTemplate = this.commonService.GetMessageTemplate(MessageTemplateType.EnterNeedsMsg);
                        message.Message = msgTemplate.TemplateText;

                        message = this.youfferMessageService.CreateMessage(message);

                        string gcmId = item.GCMId;
                        string udId = item.UDId;

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

                        if (!string.IsNullOrEmpty(udId))
                        {
                            int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, false);
                            this.pushMessageService.SendMessageNotificationToiOS(udId, message.Id.ToString(), message.Message, "Youffer", unreadMsgCount, Notification.usermsg.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.loggerservice.LogException("SendEnterNeedsMessageAndNotification:- " + ex.Message);
            }
        }
示例#7
0
        /// <summary>
        /// Broadcasts the message to youffer inbox.
        /// </summary>
        private void BroadcastMessageToYoufferInbox()
        {
            try
            {
                using (MySqlContext dbContext = new MySqlContext())
                {
                    IRepository<vtiger_contactdetails> tmp = new Repository<vtiger_contactdetails>(dbContext);
                    var lst = tmp.SqlQuery<BroadcastMessageFromCRMDto>("CALL BroadcastMessageToYoufferInbox();").ToList();
                    foreach (var item in lst)
                    {
                        MessagesDto message = new MessagesDto();
                        message.ModifiedBy = message.FromUser = message.CreatedBy = "YoufferAdmin";
                        message.IsDeleted = false;

                        string userId = string.Empty;
                        string crmUserId;
                        if (item.SendTo == "Organizations")
                        {
                            crmUserId = AppSettings.Get<string>(ConfigConstants.OrganisationId) + item.RecId;
                        }
                        else
                        {
                            crmUserId = AppSettings.Get<string>(ConfigConstants.ContactId) + item.RecId;
                        }

                        var user = this.userService.GetContactByCrmId(crmUserId);
                        if (user != null && !string.IsNullOrWhiteSpace(user.UserName))
                        {
                            userId = user.Id;
                        }

                        message.CompanyId = AppSettings.Get<string>(ConfigConstants.SuperUserId);
                        message.UserId = userId;
                        message.ToUser = userId;
                        message.Name = "Youffer Admin";
                        message.MediaId = 0;
                        message.Message = item.Message;

                        message = this.youfferMessageService.CreateMessage(message);

                        string gcmId = item.GCMId;
                        string udId = item.UDId;

                        if (!string.IsNullOrEmpty(gcmId))
                        {
                            this.pushMessageService.SendMessageNotificationToAndroid(gcmId, message.Id.ToString(), message.Message, "Youffer", item.SendTo == "Organizations" ? Notification.usermsg.ToString() : Notification.companymsg.ToString());
                        }

                        if (!string.IsNullOrEmpty(udId))
                        {
                            int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, false);
                            this.pushMessageService.SendMessageNotificationToiOS(udId, message.Id.ToString(), message.Message, "Youffer", unreadMsgCount, Notification.usermsg.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.loggerservice.LogException("BroadcastMessageToYoufferInbox:- " + ex.Message);
            }
        }
示例#8
0
        /// <summary>
        /// Sends the message to youffer inbox.
        /// </summary>
        private void SendMessageToYoufferInbox()
        {
            try
            {
                using (MySqlContext dbContext = new MySqlContext())
                {
                    IRepository<vtiger_contactdetails> tmp = new Repository<vtiger_contactdetails>(dbContext);
                    var lst = tmp.SqlQuery<SendMessageFromCrmDto>("CALL SendMessageToYoufferInbox();").ToList();
                    List<string> succ = new List<string>();
                    List<string> fail = new List<string>();
                    foreach (var item in lst)
                    {
                        MessagesDto message = new MessagesDto();
                        message.ModifiedBy = message.FromUser = message.CreatedBy = "YoufferAdmin";
                        message.IsDeleted = false;

                        string userId = string.Empty;
                        string crmUserId;
                        if (item.setype == "Accounts")
                        {
                            crmUserId = AppSettings.Get<string>(ConfigConstants.OrganisationId) + item.sendmessage_tks_sendto;
                        }
                        else
                        {
                            crmUserId = AppSettings.Get<string>(ConfigConstants.ContactId) + item.sendmessage_tks_sendto;
                        }

                        var user = this.userService.GetContactByCrmId(crmUserId);
                        if (user != null && !string.IsNullOrWhiteSpace(user.UserName))
                        {
                            userId = user.Id;
                        }

                        message.CompanyId = AppSettings.Get<string>(ConfigConstants.SuperUserId);
                        message.UserId = userId;
                        message.ToUser = userId;
                        message.Name = "Youffer Admin";
                        message.MediaId = 0;
                        message.Message = item.sendmessage_tks_message;

                        message = this.youfferMessageService.CreateMessage(message);

                        if (message.Id > 0)
                        {
                            succ.Add(item.sendmessageid.ToString());
                        }
                        else
                        {
                            fail.Add(item.sendmessageid.ToString());
                        }

                        string gcmId = item.GCMId;
                        string udId = item.UDId;

                        if (!string.IsNullOrEmpty(gcmId))
                        {
                            this.loggerservice.LogException("GCMID - " + gcmId);
                            this.pushMessageService.SendMessageNotificationToAndroid(gcmId, message.Id.ToString(), message.Message, "Youffer", item.setype == "Accounts" ? Notification.usermsg.ToString() : Notification.companymsg.ToString());
                        }

                        if (!string.IsNullOrEmpty(udId))
                        {
                            int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(message.UserId, false);
                            this.loggerservice.LogException("UDID - " + udId);
                            this.pushMessageService.SendMessageNotificationToiOS(udId, message.Id.ToString(), message.Message, "Youffer", unreadMsgCount, Notification.usermsg.ToString());
                        }
                    }

                    string passresult = succ.Any() ? succ.Aggregate((a, b) => a + "," + b) : string.Empty;
                    string failresult = fail.Any() ? fail.Aggregate((a, b) => a + "," + b) : string.Empty;
                    if (!string.IsNullOrWhiteSpace(passresult) || !string.IsNullOrWhiteSpace(failresult))
                    {
                        var res = tmp.SqlQuery<int>("CALL UpdateMessageStatus({0}, {1});", passresult, failresult).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                this.loggerservice.LogException("SendMessageToYoufferInboxFromCRM:- " + ex.Message);
            }
        }
示例#9
0
 /// <summary>
 /// Send Message to Company from User
 /// </summary>
 /// <param name="clientId"> The client Id. </param>
 /// <param name="message"> The message </param>
 public void SendMessage(string clientId, MessagesDto message)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>();
     context.Clients.Group(clientId).addMessage(message);
 }
示例#10
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);
        }