public string GetAdvertiserProfileNameByConversationId(string conversationId, string email) { AdvertiserProfileDocument publisherProfile = new AdvertiserProfileDocument(); string profileName = string.Empty; string query = string.Empty; List <string> users = GetUsersIdInConversation(conversationId); // todo collectionName = CosmosCollections.User.ToString(); // user one query = $"SELECT * FROM {collectionName} WHERE {collectionName}.id='{users[0]}'"; UserDocument userOne = context.ExecuteQuery <UserDocument>(databaseName, collectionName, query).FirstOrDefault(); // user two query = $"SELECT * FROM {collectionName} WHERE {collectionName}.id='{users[1]}'"; UserDocument userTwo = context.ExecuteQuery <UserDocument>(databaseName, collectionName, query).FirstOrDefault(); if (userOne != null && userOne.Email != email) { publisherProfile = GetAdvertiserProfile(userOne.Email); profileName = publisherProfile.Title; } if (userTwo != null && userTwo.Email != email) { publisherProfile = GetAdvertiserProfile(userTwo.Email); profileName = publisherProfile.Title; } return(profileName); }
/// <summary> /// /// </summary> /// <param name="proposal"></param> /// <param name="audienceChannel">Si se le pasa un audienceChannel este se usara para setear price and productName, sino se consultara uno a la BD</param> /// <param name=""></param> /// <returns></returns> private ProposalReviewListItemViewModel MapToProposalReviewListItemViewModel(ProposalDocument proposal, AudienceChannelDocument audienceChannel = null) { if (audienceChannel == null) { audienceChannel = _audienceChannelManager.GetAudienceChannelById(proposal.AudienceChannelId); } AdvertiserProfileDocument advertiserProfile = _advertiserProfileManager.FindProfileByProfileId(proposal.AdvertiserProfileId); ApplicationUser user = _identityManager.FindUserByUserId(advertiserProfile.UserId); CountryDocument country = _catalogManager.FindCountryById(advertiserProfile.CountryBusinessInId); DateTime registerProposal = Convert.ToDateTime(proposal.RegisterDate); string messageDaysAgo = DateUtils.GetTextDaysAgo(registerProposal); return(new ProposalReviewListItemViewModel() { TimeAgoReceived = messageDaysAgo, AdvertiserImageSrc = advertiserProfile.IconUrl, AdvertiserName = user.Name, IdProposal = proposal.Id, Location = country != null?country.Name:"", Price = audienceChannel.Price.ToString() + " kind", ProductName = audienceChannel.Name }); }
public List <string> GetUserIdsWithProfileId(List <string> profileIds) { List <string> userIds = new List <string>(); try { foreach (var profileId in profileIds) { AdvertiserProfileDocument adervertiserProfile = GetAdvertiserProfileByProfileId(profileId); PublisherProfileDocument publisherProfile = GetPublisherProfileByProfileId(profileId); if (adervertiserProfile != null) { userIds.Add(adervertiserProfile.UserId); } if (publisherProfile != null) { userIds.Add(publisherProfile.UserId); } } } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } return(userIds); }
public AdvertiserProfileViewModel() { manager = new AdvertiserProfileManager(); profile = new AdvertiserProfileDocument(); preferences = new List <AdvertiserPreferenceDocument>(); preferencesStringify = string.Empty; telemetria = new Trace(); }
public AdvertiserProfileDocument FindProfileByProfileId(string advertiserProfileId) { string query = $"SELECT * FROM {CosmosCollections.AdvertiserProfile.ToString()} WHERE {CosmosCollections.AdvertiserProfile.ToString()}.id='{advertiserProfileId}'"; AdvertiserProfileDocument advertiserProfile = context.ExecuteQuery <AdvertiserProfileDocument>(databaseName, CosmosCollections.AdvertiserProfile.ToString(), query).SingleOrDefault(); if (advertiserProfile == null) { return(null); } return(advertiserProfile); }
public AdvertiserProfileViewModel FindProfileByUserId(string userId) { AdvertiserProfileDocument profile = context.GetAllDocuments <AdvertiserProfileDocument>(databaseName, CosmosCollections.AdvertiserProfile.ToString()).SingleOrDefault(u => u.UserId == userId); if (profile == null) { return(null); } return(new AdvertiserProfileViewModel { profile = profile }); }
public AdvertiserProfileDocument GetAdvertiserProfileByProfileId(string profileId) { AdvertiserProfileDocument profile = null; try { collectionName = CosmosCollections.AdvertiserProfile.ToString(); string query = $"SELECT * FROM {collectionName} WHERE {collectionName}.id='{profileId}'"; profile = context.ExecuteQuery <AdvertiserProfileDocument>(databaseName, collectionName, query).FirstOrDefault(); } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } return(profile); }
public void Update(AdvertiserProfileDocument profile, List <AdvertiserPreferenceDocument> preferences) { try { context.UpsertDocument <AdvertiserProfileDocument>(databaseName, CosmosCollections.AdvertiserProfile.ToString(), profile); string query = $"SELECT * FROM {CosmosCollections.AdvertiserProfilePreference.ToString()} WHERE {CosmosCollections.AdvertiserProfilePreference.ToString()}.AdvertiserProfileId='{profile.Id}'"; List <AdvertiserPreferenceDocument> currentPreferences = context.ExecuteQuery <AdvertiserPreferenceDocument>(databaseName, CosmosCollections.AdvertiserProfilePreference.ToString(), query); context.DeleteDocumentsById(databaseName, CosmosCollections.AdvertiserProfilePreference.ToString(), currentPreferences.Select(c => c.Id).ToList()); foreach (var preference in preferences) { context.AddDocument <AdvertiserPreferenceDocument>(databaseName, CosmosCollections.AdvertiserProfilePreference.ToString(), preference); } } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } }
public ActionResult AddMessage([FromBody] CurrentConversation proposalParametersNavigation) { proposalParametersNavigation.MessageWithoutHtml = proposalParametersNavigation.Message; proposalParametersNavigation.Message = Manager.MakeRefIfContainLink(proposalParametersNavigation.Message); string serviceBusTopicName = "conversationtopicdev"; // obtenerlo del web.config string profileName = string.Empty; PublisherProfileDocument publisherProfile = new PublisherProfileDocument(); AdvertiserProfileDocument advertiserProfile = new AdvertiserProfileDocument(); List <string> usersIdInConversation = Manager.GetUsersIdInConversation(proposalParametersNavigation.Id); var email = System.Web.HttpContext.Current.User.Identity.Name; KindAds.Utils.Enums.Roles rol; rol = (User.IsInRole(KindAds.Utils.Enums.Roles.Publisher.ToString()) ? KindAds.Utils.Enums.Roles.Publisher : KindAds.Utils.Enums.Roles.Advertiser); int rolId = Convert.ToInt32(rol); if (rolId == 1) { publisherProfile = Manager.GetPublisherProfile(email); profileName = publisherProfile.Name; } else { advertiserProfile = Manager.GetAdvertiserProfile(email); profileName = advertiserProfile.Title; } proposalParametersNavigation.ProfileName = profileName; ConversationMessageNotification message = new ConversationMessageNotification() { currentConversation = proposalParametersNavigation, users = usersIdInConversation }; Manager.AddMessageToCosmos(message); notificationManager = new NotificationManager(serviceBusTopicName); notificationManager.ProcessConversationNotification(message); notificationManager.Close(); return(Json(new { Result = "Send message OK" }, JsonRequestBehavior.AllowGet)); }
public PublisherProposalDetailViewModel FindPublisherProposalDetailVMById(string proposalId) { ProposalDocument proposal = FindProposalById(proposalId); AdvertiserProfileDocument advertiser = _advertiserProfileManager.FindProfileByProfileId(proposal.AdvertiserProfileId); AudienceChannelDocument audienceChannel = GetAudienceChannelById(proposal.AudienceChannelId); string audienceUrl = getAudienceUrlSite(audienceChannel.AudienceId); CountryDocument country = _catalogManager.FindCountryById(advertiser.CountryBusinessInId); return(new PublisherProposalDetailViewModel { Accepted = proposal.AcceptedByPublisher, AdvertiserImage = advertiser.IconUrl, AdvertiserLocation = country.Name, AdvertiserName = advertiser.Title, ProposalId = proposal.Id, QuestionsAndAnswers = proposal.Questions, RejectDetail = proposal.RejectDetail, WebSite = audienceUrl, MemberSinceYear = advertiser.RegisterDate, Price = proposal.Price }); }
public List<ConversationItemViewModel> GetAllConversations(string email,int rolId) { ConcurrentBag<ConversationItemViewModel> conversationItemsParallel = new ConcurrentBag<ConversationItemViewModel>(); List<ConversationItemViewModel> conversationItems = new List<ConversationItemViewModel>(); List<ConversationDocument> conversations = new List<ConversationDocument>(); conversations = manager.GetConversationsAsync(email, rolId); string profileName = string.Empty; // from profile string profileTagLine = string.Empty; // from audience when is publisher string iconUrl = string.Empty; // from profile PublisherProfileDocument publisherProfile= manager.GetPublisherProfile(email); AdvertiserProfileDocument advertiserProfile = manager.GetAdvertiserProfile(email); if(publisherProfile != null && rolId==1) { profileName = publisherProfile.Name; iconUrl = publisherProfile.IconUrl; Parallel.ForEach(conversations, (conversation) => { List<ConversationMessageDocument> messages = manager.GetConversationMessagesByConversationId(conversation.Id); ConversationMessageDocument lastMessage = new ConversationMessageDocument(); if (messages.Count() > 0) { lastMessage = (from message in messages orderby message.RegisterDate descending select message).FirstOrDefault(); } AudienceChannelDocument audienceChannel = manager.GetAudienceChannelById(conversation.AudienceChannelId); profileTagLine = audienceChannel.TagLine; ConversationItemViewModel viewModel = new ConversationItemViewModel() { ProfileName = manager.GetAdvertiserProfileNameByConversationId(conversation.Id, email), ProfileTagLine = profileTagLine, IconUrl = manager.GetAdvertiserImageByConversationId(conversation.Id, email), Messages = messages, LastMessage = lastMessage, ConversationId = conversation.Id, Chunks = manager.GetConversationMessagesPerChunk(messages) }; conversationItemsParallel.Add(viewModel); }); } if(advertiserProfile!=null && rolId==2) { profileName = advertiserProfile.Title; iconUrl = advertiserProfile.IconUrl; profileTagLine = advertiserProfile.Tagline; Parallel.ForEach(conversations, (conversation) => { List<ConversationMessageDocument> messages = manager.GetConversationMessagesByConversationId(conversation.Id); ConversationMessageDocument lastMessage = new ConversationMessageDocument() { Message = string.Empty }; if (messages.Count() > 0) { lastMessage = (from message in messages orderby message.RegisterDate descending select message).FirstOrDefault(); } ConversationItemViewModel viewModel = new ConversationItemViewModel() { ProfileName = manager.GetPublisherProfileNameByConversationId(conversation.Id, email), ProfileTagLine = profileTagLine, IconUrl = manager.GetPublisherImageByConversationId(conversation.Id, email), Messages = messages, LastMessage = lastMessage, ConversationId = conversation.Id, Chunks = manager.GetConversationMessagesPerChunk(messages) }; conversationItemsParallel.Add(viewModel); }); } conversationItems = conversationItemsParallel.ToList(); conversationItems.OrderByDescending(x => x.LastMessage.MessageTime); return conversationItems; }