Ejemplo n.º 1
0
        /// <summary>
        /// Maps messages by Hotel Id
        /// </summary>
        /// <param name="messageList"></param>
        /// <param name="messageTypeList"></param>
        /// <returns>BaseResult<List<MessagesViewModel>></returns>
        public static BaseResult <List <MessagesViewModel> > MapMessagesByHotelId(BaseResult <List <Message> > messageList, BaseResult <List <MessageType> > messageTypeList)
        {
            BaseResult <List <MessagesViewModel> > responseModelList = new BaseResult <List <MessagesViewModel> >();
            List <MessagesViewModel> modelList = new List <MessagesViewModel>();

            foreach (var item in messageList.Result)
            {
                string messageType = null;
                if (messageTypeList.Result.Where(x => x.Id == item.MessageTypeId).Any())
                {
                    messageType = messageTypeList.Result.Find(x => x.Id == item.MessageTypeId).Name;
                }
                MessagesViewModel messageModel = new MessagesViewModel
                {
                    MessageId          = item.Id,
                    MessageTitle       = item.MessageTitle,
                    MessageTypeName    = messageType,
                    MessageDescription = item.MessageDescription,
                    LastModifiedBy     = item.UpdatedBy,
                    StartDate          = item.StartDate,
                    EndDate            = item.EndDate,
                    IsActive           = item.IsActive
                };
                modelList.Add(messageModel);
            }
            responseModelList.Result = modelList;
            return(responseModelList);
        }
Ejemplo n.º 2
0
 protected override void OnDetachingFrom(MessagePage bindable)
 {
     this.viewModel.Messages.CollectionChanged -= Messages_CollectionChanged;
     this.sfChat    = null;
     this.viewModel = null;
     base.OnDetachingFrom(bindable);
 }
Ejemplo n.º 3
0
        //
        // GET: Forum/EditMessage/Groupid&ThreadId&MessageId
        public async Task <ActionResult> EditMessage(int groupId, int threadId, int messageId)
        {
            // Just sending the id too the viewbag so if we need them in the view we have them
            ViewBag.GroupId   = groupId;
            ViewBag.ThreadId  = threadId;
            ViewBag.MessageId = messageId;

            Message message = await MessageManager.FindByIdAsync(messageId);

            // The model for the orgirinal message
            // Creating the block
            MessagesViewModel messageModel = new MessagesViewModel
            {
                Id            = message.Id,
                UserName      = message.User.UserName,
                JoinDate      = message.User.JoinDate,
                Posts         = message.User.PostsCount,
                Signiture     = message.User.Signature,
                Reputation    = message.Reputation,
                ThreadId      = threadId,
                GroupId       = groupId,
                Image         = ProfilePictureSystem.GetProfilePicture(message.User.UserId),
                Country       = (await UserManager.FindByIdAsync(message.User.UserId)).Country,
                Body          = message.Body,
                MessagePost   = message.TimeStamp,
                MessageNumber = message.MessagePlacementInThread
            };

            // This will be passed true to the partial view
            ViewBag.MessageModel = messageModel;

            return(View());
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Вывод сообщений в теме
            /// </summary>
            /// <param name="TopicID"></param>
            public ActionResult MessagesList(int TopicID)
            {
                try
                {
                    List <MessagesViewModel> messages = new List <MessagesViewModel>();
                    var TopicBLL = Data.GetTopicByID(TopicID);

                    var MessagesBLL = Data.GetMessages(TopicBLL.TopicID);

                    ViewBag.SectionID  = TopicBLL.SectionID;
                    ViewBag.TopicID    = TopicBLL.TopicID;
                    ViewBag.TopicName  = TopicBLL.TopicName;
                    ViewBag.TopicText  = TopicBLL.TopicText;
                    ViewBag.AuthorName = TopicBLL.Name;
                    ViewBag.CreateDate = TopicBLL.CreateDate;
                    ViewBag.Avatar     = TopicBLL.Avatar;

                    foreach (var m in MessagesBLL)
                    {
                        MessagesViewModel message = new MessagesViewModel();
                        message.MessageID = m.MessageID;
                        message.Name      = m.Name;
                        message.SendDate  = m.SendDate;
                        message.Text      = m.Text;
                        message.StatusID  = m.StatusID;
                        message.Avatar    = m.Avatar;
                        messages.Add(message);
                    }
                    return(PartialView(messages));
                }
                catch (ValidationException ex)
                {
                    return(Content(ex.Message));
                }
            }
Ejemplo n.º 5
0
        public ActionResult SendMessage(MessagesViewModel message)
        {
            var myId = User.Identity.GetUserId();

            var newMessage = new Message
            {
                Id         = Guid.NewGuid(),
                Content    = message.SingleMessage.Content,
                SenderId   = myId,
                ReceiverId = message.ReceiverId,
                TimeSent   = DateTime.Now
            };

            _context.Messages.Add(newMessage);


            var notification = new Notification(NotificationType.NewMessage, myId);

            var receiver = _context.Users.Single(u => u.Id == message.ReceiverId);

            receiver.Notify(notification);



            _context.SaveChanges();

            return(RedirectToAction("MessageRoom", new { id = message.ReceiverId }));
        }
Ejemplo n.º 6
0
        public MessagesViewModel ModelForMessages(MessagesViewModel viewModel)
        {
            // Проверяю или существует директория для файлов для этого юзера, если нет - создаю
            string directoryFilesImg = $"wwwroot/usersfiles/{UserID}/imgForEmail/";

            if (!Directory.Exists(directoryFilesImg))
            {
                Directory.CreateDirectory(directoryFilesImg);
            }

            string directoryFilesVoice = $"wwwroot/usersfiles/{UserID}/voiceMessage/";

            if (!Directory.Exists(directoryFilesVoice))
            {
                Directory.CreateDirectory(directoryFilesVoice);
            }

            var isForbidden = _dbContext.ForbiddenWordUsers.FirstOrDefault(a => a.UserId == UserID);

            if (isForbidden != null)
            {
                var forbidden = _dbContext.ForbiddenWordUsers.Where(a => a.UserId == UserID);
                foreach (var f in forbidden)
                {
                    viewModel.StringForbiddenWordsUser = viewModel.StringForbiddenWordsUser + " " + f.Word;
                }
            }

            viewModel.SendTo     = UserEmail;
            viewModel.UserName   = CurrentUserName;
            viewModel.AvatarPath = CurrentAvatarPath;
            return(viewModel);
        }
Ejemplo n.º 7
0
        public IActionResult GenerateVoice(string text)
        {
            if (text != null && text != "")
            {
                var generateMP3 = new Generate();
                var dirPath     = $"wwwroot/usersfiles/{UserID}/voiceMessage/";

                // Create List Forbidden Words (Standart Forbidden Words + User )
                var forbiddenWordsUser    = _dbContext.ForbiddenWordUsers.Where(u => u.UserId == UserID);
                var forbiddenWordStandart = _dbContext.ForbiddenWords.Where(a => a.Word != null);

                // for Change forbidden words to " цензура "
                MessagesViewModel viewModel = new MessagesViewModel();
                text = RemoveWords(text, forbiddenWordsUser, forbiddenWordStandart, viewModel, " цензура ");

                string fileName = GetMd5Hash(text);
                generateMP3.tts(text, "ru", dirPath, fileName);
                string pathForPlay = $"../usersfiles/{UserID}/voiceMessage/{fileName}.mp3";

                return(Json(pathForPlay));
            }
            else
            {
                return(Json("noVoice"));
            }
        }
Ejemplo n.º 8
0
        public static string RemoveWords(string textForReplace,
                                         IQueryable <ForbiddenWordUser> forbiddenWordUser,
                                         IQueryable <ForbiddenWord> forbiddenWordStandart,
                                         MessagesViewModel viewModel,
                                         string replaceTo)
        {
            foreach (var word in forbiddenWordUser)
            {
                var forbidden = new ForbiddenWordUser();
                forbidden.Word = word.Word;
                viewModel.ForbiddenWordsUser.Add(forbidden);
                viewModel.AllForbiddenWordsUser.Add(forbidden);
            }
            foreach (var word in forbiddenWordStandart)
            {
                var forbidden = new ForbiddenWordUser();
                forbidden.Word = word.Word;
                viewModel.ForbiddenWordsStandart.Add(forbidden);
                viewModel.AllForbiddenWordsUser.Add(forbidden);
            }

            List <string> arrayForbidden = new List <string>();

            foreach (var w in viewModel.AllForbiddenWordsUser)
            {
                arrayForbidden.Add(w.Word.ToLower());
            }

            string pattern = "\\b" + string.Join("\\b|\\b", arrayForbidden) + "\\b";
            string newText = Regex.Replace(textForReplace, pattern, replaceTo, RegexOptions.IgnoreCase);

            return(newText);
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> GetAllUnreadMessages(int id = 1)
        {
            var userid  = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var tweetId = this._context.TwitterUsers
                          .SingleOrDefault(t => t.UserID == userid)
                          .ID;


            var messages = await _context.Messages
                           .Where(m => ((m.From == id && m.To == tweetId)) && m.IsSeen == false)
                           .ToListAsync();

            if (messages.Count > 0)
            {
                foreach (var message in messages)
                {
                    if (message.To == tweetId)
                    {
                        message.IsSeen = true;
                        _context.Update(message);
                    }
                }

                await _context.SaveChangesAsync();
            }


            var model = new MessagesViewModel();

            model.Id       = id;
            model.Messages = messages;

            return(PartialView("GetAllUnReadMessages", model));
        }
Ejemplo n.º 10
0
            public async Task CanExecuteWhenMessageIsNotNullOrEmpty()
            {
                await BlobCache.Secure.SaveLogin("Gitter", "TheAccessToken", "Gitter");

                var room = new Room {
                    name = "TheRoom", id = "TheRoomId"
                };
                var api = Substitute.For <IGitterApi>();

                api.GetMessages(Arg.Any <string>(), Arg.Any <string>()).Returns(Observable.Return((IReadOnlyList <Message>) new List <Message>()));
                var fixture = new MessagesViewModel(room, api, Substitute.For <IScreen>());
                await fixture.LoadMessages.ExecuteAsync();

                fixture.MessageText = "TheMessage";
                Assert.True(fixture.SendMessage.CanExecute(null));

                fixture.MessageText = null;
                Assert.False(fixture.SendMessage.CanExecute(null));

                fixture.MessageText = String.Empty;
                Assert.False(fixture.SendMessage.CanExecute(null));

                fixture.MessageText = " ";
                Assert.False(fixture.SendMessage.CanExecute(null));
            }
Ejemplo n.º 11
0
        public async Task <IActionResult> Messages(string userName)
        {
            if (!String.IsNullOrEmpty(userName))
            {
                Artist receiver = await _userManager.FindByNameAsync(userName);

                if (receiver == null)
                {
                    return(NotFound());
                }

                Artist sender = await _userManager.GetUserAsync(User);

                IQueryable <Message> messages =
                    _context.Messages
                    .Where(m => (m.Receiver == receiver && m.Sender == sender) || (m.Receiver == sender && m.Sender == receiver))
                    .OrderBy(m => m.CreationDate);

                MessagesViewModel viewModel = new MessagesViewModel
                {
                    Sender   = sender,
                    Receiver = receiver,
                    Messages = messages.ToList()
                };

                return(View(viewModel));
            }
            return(NotFound());
        }
Ejemplo n.º 12
0
        public ActionResult NewMessage(List <MessagesViewModel> messages)
        {
            MessagesViewModel message = messages[0];

            if (message.Text != null)
            {
                dataManager.Messages.SaveOutgoingMessage(
                    new OutgoingMessage
                {
                    UserId      = message.UserFromId,
                    UserToId    = message.UserToId,
                    CreatedDate = DateTime.UtcNow,
                    Text        = message.Text
                });
                dataManager.Messages.SaveIncomingMessage(
                    new IncomingMessage
                {
                    UserId      = message.UserToId,
                    UserFromId  = message.UserFromId,
                    CreatedDate = DateTime.UtcNow,
                    Text        = message.Text
                });
                TempData["id"] = message.UserToId;
                return(Redirect(System.Web.HttpContext.Current.Request.UrlReferrer.ToString()));
            }
            return(Redirect(System.Web.HttpContext.Current.Request.UrlReferrer.ToString()));
        }
Ejemplo n.º 13
0
        public MessagesPage()
        {
            InitializeComponent();

            _viewModel     = new MessagesViewModel();
            BindingContext = _viewModel;
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> CreateMessages(MessagesViewModel model)
        {
            var user = this._context.Users.FirstOrDefault(u => u.Id == model.UserId);
            var chat = this._context.Chats.FirstOrDefault(s => s.Id == model.ChatId);

            if (user != null)
            {
                if (chat != null)
                {
                    var Message = new Message()
                    {
                        Id        = Guid.NewGuid(),
                        ChatId    = model.ChatId,
                        UserId    = model.UserId,
                        Name      = model.Name,
                        Text      = model.Message,
                        Timestamp = DateTime.UtcNow
                    };

                    this._context.Messages.Add(Message);
                    await _context.SaveChangesAsync();
                }
            }

            return(RedirectToAction("ChatShop", new { shopId = model.ChatId }));
        }
Ejemplo n.º 15
0
        public MainViewModel(IScreen screen, ISettingsManager settingsManager, IVersionManager versionManager)
        {
            HostScreen = screen;

            Games     = new GamesViewModel(Locator.Current);
            Downloads = new DownloadsViewModel(Locator.Current.GetService <IJobManager>());
            Messsages = new MessagesViewModel(Locator.Current.GetService <IDatabaseManager>(), Locator.Current.GetService <IMessageManager>());

            GotoSettings = ReactiveCommand.CreateFromObservable(() => screen.Router.Navigate.Execute(new SettingsViewModel(screen, settingsManager, versionManager, Locator.Current.GetService <IGameManager>())));

            // login status
            settingsManager.WhenAnyValue(sm => sm.AuthenticatedUser)
            .Select(u => u == null ? "Not logged." : $"Logged as {u.Name}")
            .ToProperty(this, x => x.LoginStatus, out _loginStatus);

            // show notice when new version arrives but hide when button was clicked
            versionManager.NewVersionAvailable
            .Where(release => release != null)
            .Subscribe(newRelease => {
                ShowUpdateNotice = true;
            });

            // update notice close button
            CloseUpdateNotice = ReactiveCommand.Create(() => { ShowUpdateNotice = false; });

            // restart button
            RestartApp = ReactiveCommand.Create(() => { UpdateManager.RestartApp(); });
        }
Ejemplo n.º 16
0
        // GET: Messages
        public ActionResult Index()
        {
            user user = (user)Session[ECGlobalConstants.CurrentUserMarcker];

            if (user == null || user.id == 0)
            {
                return(RedirectToAction("Index", "Account"));
            }

            #region EC-CC Viewbag
            ViewBag.is_cc = is_cc;
            string cc_ext = "";
            if (is_cc)
            {
                cc_ext = "_cc";
            }
            ViewBag.cc_extension = cc_ext;
            #endregion


            int       user_id = user.id;
            UserModel um      = new UserModel(user_id);
            ViewBag.um = um;

            ViewBag.user_id = user_id;
            MessagesViewModel _messages = new MessagesViewModel(user.id);

            ViewBag.Message = _messages;
            //ViewBag.um = um;
            return(View());
        }
        public Messages()
        {
            InitializeComponent();
            vm             = new MessagesViewModel(Navigation, "Messages");
            BindingContext = vm;
            //vm.IsBusy = true;
            vm.OverlayText = "Pulling messages";
            //DelayActionAsync(6000, () => vm.IsBusy = false);
            if (vm.MessagesList.Count > 0)
            {
                //Move to end of list by default when opening Messages view
                var target = vm.MessagesList[vm.MessagesList.Count - 1];
                MessagesListView.ScrollTo(target, ScrollToPosition.End, true);
            }

            vm.MessagesList.CollectionChanged += (sender, e) =>
            {
                var target = vm.MessagesList[vm.MessagesList.Count - 1];
                MessagesListView.ScrollTo(target, ScrollToPosition.End, true);
            };

            vm.MessagesList.Add(new Models.Message()
            {
                Text = "Hola que tal!", IsTextIn = true, MessageDateTime = new DateTime()
            });
        }
        private void SetConversationParticipants()
        {
            MessagesViewModel viewModel = this.DataContext as MessagesViewModel;

            viewModel.ConversationBuddy = viewModel.People[0];
            viewModel.You = viewModel.People[1];
        }
Ejemplo n.º 19
0
        public MessagesViewModel GetMessagesPreparedPage(string userId)
        {
            var model       = new MessagesViewModel();
            var returnModel = this.GetMessagesChangePage(model, userId, 1);

            return(returnModel);
        }
Ejemplo n.º 20
0
        // GET: Messages
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();

            if (userId == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            using (var db = new ZapContext())
            {
                var user = db.Users
                           .Include("Alerts")
                           .Include("Messages")
                           .Include("Alerts.PostLink")
                           .Include("Messages.PostLink")
                           .Where(u => u.AppId == userId).First();

                var messages = user.Messages.Where(m => !m.IsRead && !m.IsDeleted).ToList();

                var alerts = user.Alerts.Where(m => !m.IsRead && !m.IsDeleted).ToList();

                var vm = new MessagesViewModel()
                {
                    Messages = messages,
                    Alerts   = alerts,
                };

                return(View(vm));
            }
        }
Ejemplo n.º 21
0
        public ActionResult Index()
        {
            GetMessagesQueryResult result = Query.For <GetMessagesQueryResult>().Empty();
            MessagesViewModel      vm     = ToViewModel(result);

            return(View(vm));
        }
Ejemplo n.º 22
0
        private void RefreshMessages()
        {
            if (_vmMessages == null)
            {
                _vmMessages = new MessagesViewModel(_flMessages);
                MessagesListBox.DataContext = _vmMessages;
                MainTabControl.DataContext  = _vmMessages;
            }

            LookupFieldNames();
            if (_messagesRouteNameFieldName == null)
            {
                return;
            }

            string where = "1=1";
            if (!String.IsNullOrWhiteSpace(_routeName))
            {
                where = (_messagesRouteNameFieldName + "='" + _routeName + "'");
            }

            _vmMessages.Update(_flMessages, where);

            // update the tab's image
            MessagesTabImage.Source = _vmMessages.InternalResourceTabImageSource;

            BindSelectedMessage();
        }
Ejemplo n.º 23
0
 protected override void OnDestroy()
 {
     MessagesViewModel.UnsubscribeMessages(this);
     Task.Run(async() =>
              await MessagesViewModel.MarkAllMessagesAsRead());
     base.OnDestroy();
 }
Ejemplo n.º 24
0
        public ActionResult Index()
        {
            string user = User.Identity.GetUserName();

            using (var db = new MessagingContext())
            {
                var query = from m in db.Messages
                            orderby m.Time
                            where m.ToUserID == user && !m.Seen
                            select new MessageViewModel
                {
                    fromUser    = m.FromUserID,
                    MessageText = m.MessageText,
                    Time        = m.Time,
                    Image       = m.Image
                };


                MessagesViewModel messagesVM = new MessagesViewModel();
                messagesVM.Messages = query.ToList();



                return(View(messagesVM));
            }
        }
Ejemplo n.º 25
0
        public MessagesPage(string id)
        {
            InitializeComponent();
            LoggId = id;

            BindingContext = viewModel = new MessagesViewModel(LoggId);
        }
        public Messages(Contact contact)
        {
            InitializeComponent();
            vm             = new MessagesViewModel(Navigation, "Messages");
            BindingContext = vm;
            vm.Contact     = contact;
            //vm.IsBusy = true;
            vm.OverlayText = "Pulling messages";
            //DelayActionAsync(6000, () => vm.IsBusy = false);
            if (vm.MessagesList.Count > 0)
            {
                //Move to end of list by default when opening Messages view
                var target = vm.MessagesList[vm.MessagesList.Count - 1];
                MessagesListView.ScrollTo(target, ScrollToPosition.End, true);
            }

            vm.OnMessageReceived += (s, msg) =>
            {
                //Execute on main thread. Event raising comes fron another thread
                //Creating a new event takes avoids timing issues between PropertyChanged mechanism and UI
                Device.BeginInvokeOnMainThread(() => MessagesListView.ScrollTo(msg, ScrollToPosition.End, true));
            };


            //vm.MessagesList.Add(new Models.Message() { Text = "Hola que tal!", IsTextIn = true, MessageDateTime = new DateTime() });
        }
Ejemplo n.º 27
0
        public ActionResult Create(MessagesViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else if (model.SentTo == null || model.ThisMessage == null || model.ThisMessage == "" || model.ThisMessage == "null")
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                using (var db = DbFactory.Create())
                {
                    db.Messages.Add(new Messages()
                    {
                        SentFrom    = User.Identity.Name,
                        SentTo      = model.SentTo,
                        IsRead      = false,
                        ThisMessage = model.ThisMessage,
                        MessageTime = DateTime.Now
                    });
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(model));
            }
        }
Ejemplo n.º 28
0
 public DetailedListPage(string Source, string Area)
 {
     InitializeComponent();
     this.Source         = Source;
     this.Area           = Area;
     messagesViewModel   = new MessagesViewModel();
     this.BindingContext = messagesViewModel;
 }
Ejemplo n.º 29
0
        public ActionResult DeleteConfirmed(int id)
        {
            MessagesViewModel messagesViewModel = db.MessagesViewModels.Find(id);

            db.MessagesViewModels.Remove(messagesViewModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 30
0
        public async Task SendMessage_DoesNotCallSendMessage_WhenMessageIsEmpty(
            [Frozen] Mock <IMessageService> messageServiceMock, MessagesViewModel viewModel)
        {
            await viewModel.SendMessageCommand.ExecuteAsync();

            messageServiceMock.Verify(ms => ms.SendMessageAsync(string.Empty, It.IsAny <CancellationToken>()),
                                      Times.Never);
        }
Ejemplo n.º 31
0
 public EventViewModel With(Models.Event evt)
 {
     Id = evt.EventId;
     Name = evt.Name ?? "None";
     Messages = new MessagesViewModel().With(evt.Messages).Using("Event", evt.EventId).ShowPostForm();
     Date = evt.DateTime.ToShortDateString();
     Location = evt.Location ?? "Unknown";
     Description = evt.Description ?? "None";
     return this;
 }
Ejemplo n.º 32
0
        public CampaignViewModel With(Models.Campaign campaigns)
        {
            Name = campaigns.Name;

            Messages =
                new MessagesViewModel().With(campaigns.Messages).Using("Campaign", campaigns.CampaignId).ShowPostForm();

            Evts = new Dictionary<int, string>();

            Members = new Dictionary<int, string>();

            CampaignId = campaigns.CampaignId;

            foreach (Models.Event evt in campaigns.Events)
            {
                if (evt.Name.Length > 20)
                {
                    string summary = string.Format("{0}: {1} ...", evt.DateTime.ToShortDateString(),
                                                   evt.Name.Substring(0, 20));
                    Evts.Add(evt.EventId, summary);
                }
                else
                {
                    string summary = string.Format("{0}: {1}", evt.DateTime.ToShortDateString(), evt.Name);
                    Evts.Add(evt.EventId, summary);
                }
            }

            foreach (UserProfile mem in campaigns.Members)
            {
                if (mem.DisplayName.Length > 20)
                {
                    string summary = string.Format("{0} ...", mem.DisplayName.Substring(0, 20));
                    Members.Add(mem.UserId, summary);
                }
                else
                {
                    Members.Add(mem.UserId, mem.DisplayName);
                }
            }

            Description = campaigns.Description;

            CreateEventModel = new CreateEventViewModel { Ctrler = "Campaign", ObjId = campaigns.CampaignId };

            IsSubscribed = true;

            return this;
        }
Ejemplo n.º 33
0
 public GroupViewModel With(Models.Group group)
 {
     IsPublic = group.IsPublic;
     Name = group.Name;
     Messages = new MessagesViewModel().With(group.Messages).Using("Group", group.GroupId).ShowPostForm();
     Evts = new Dictionary<int, string>();
     Members = new Dictionary<int, string>();
     Id = group.GroupId;
     Description = group.Description;
     foreach (Models.Event evt in group.Events)
     {
         if (evt.Name.Length > 20)
         {
             string summary = string.Format("{0}: {1} ...", evt.DateTime.ToShortDateString(),
                                            evt.Name.Substring(0, 20));
             Evts.Add(evt.EventId, summary);
         }
         else
         {
             string summary = string.Format("{0}: {1}", evt.DateTime.ToShortDateString(), evt.Name);
             Evts.Add(evt.EventId, summary);
         }
     }
     foreach (UserProfile mem in group.Members)
     {
         if (mem.DisplayName.Length > 20)
         {
             string summary = string.Format("{0} ...", mem.DisplayName.Substring(0, 20));
             Members.Add(mem.UserId, summary);
         }
         else
         {
             Members.Add(mem.UserId, mem.DisplayName);
         }
     }
     CreateEventModel = new CreateEventViewModel { Ctrler = "Group", ObjId = group.GroupId };
     IsSubscribed = true;
     return this;
 }
Ejemplo n.º 34
0
        public IndexViewModel With(UserProfile user)
        {
            Campaigns = new Dictionary<int, string>();
            Groups = new Dictionary<int, string>();
            Evts = new Dictionary<int, string>();

            Neightbours = new Dictionary<int, string>();

            foreach (UserProfile n in user.Community.Members)
            {
                if (n.UserId != user.UserId)
                {
                    if (n.DisplayName.Length > 20)
                    {
                        Neightbours.Add(n.UserId, string.Format("{0} ...", n.DisplayName.Substring(0, 20)));
                    }
                    else
                    {
                        Neightbours.Add(n.UserId, n.DisplayName);
                    }
                }
            }
            foreach (Models.Campaign campaign in user.Campaigns)
            {
                if (campaign.Name.Length > 20)
                {
                    Campaigns.Add(campaign.CampaignId, string.Format("{0} ...", campaign.Name.Substring(0, 20)));
                }
                else
                {
                    Campaigns.Add(campaign.CampaignId, campaign.Name);
                }
            }

            UnreadMessages = user.ReceivedMessages.Count(m => m.IsRead == false);

            foreach (Models.Group group in user.Groups)
            {
                if (group.Name.Length > 20)
                {
                    Groups.Add(group.GroupId, string.Format("{0} ...", group.Name.Substring(0, 20)));
                }
                else
                {
                    Groups.Add(group.GroupId, group.Name);
                }
            }

            foreach (Models.Event evt in user.Community.Events)
            {
                if (evt.Name.Length > 20)
                {
                    string summary = string.Format("{0}: {1} ...", evt.DateTime.ToShortDateString(),
                                                   evt.Name.Substring(0, 20));
                    Evts.Add(evt.EventId, summary);
                }
                else
                {
                    string summary = string.Format("{0}: {1}", evt.DateTime.ToShortDateString(), evt.Name);
                    Evts.Add(evt.EventId, summary);
                }
            }

            Comments =
                new MessagesViewModel().With(user.Community.Messages.OrderByDescending(m => m.MessageId))
                                       .Using("Community", user.CommunityID)
                                       .ShowPostForm();

            return this;
        }