public ActionResult SendMessage(MessageIndexViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = this.users.GetById(User.Identity.GetUserId());
                var message = new Message() { Content = model.SendInput.Content };
                message.UserId = user.Id;
                this.messages.Add(message);

                //Squad sending to Platoon
                if (user.Squad != null)
                {
                    var squad = this.squads.GetById(user.SquadId.GetValueOrDefault());
                    var platoon = this.platoons.GetById(squad.PlatoonId.GetValueOrDefault());
                    platoon.Messages.Add(message);
                    this.platoons.Update(platoon);
                }
                else
                {
                    var squad = this.squads.GetById(user.SquadId.GetValueOrDefault());
                    squad.Messages.Add(message);
                    this.squads.Update(squad);
                }

            }

            object a = "yey";
            return Json(a);
        }
        public ActionResult Message()
        {
            var user = this.users.GetById(User.Identity.GetUserId());
            var messages = new MessageBoxViewModel();
            var allMessages = new List<Message>();
            var squad = this.squads.GetById(user.SquadId.GetValueOrDefault());
            if (user.Squad != null)
            {
                allMessages = squad
                    .Messages
                    .ToList();
            }
            else
            {
                var platoon = this.platoons
                    .GetAll()
                    .FirstOrDefault(x => x.PlatoonCommanderId == user.Id);
                allMessages = platoon.Messages.ToList();
            }

            allMessages.Reverse();
            messages.Content = allMessages.ToList();
            @ViewBag.HeaderText = "Send message to commander";
            var data = new MessageIndexViewModel() { SendInput = new SendMessageViewModel(), MessageView = messages };
            return PartialView("_SendMessage", data);
        }
示例#3
0
        //先查询,再筛选,再排序,最后再分页
        public async Task <IActionResult> Index(string searchString, GenderEnum?gender
                                                , string sorting = "Id", int crruentPage = 1, int pageCount = 10)
        {
            MessageIndexViewModel model = new MessageIndexViewModel();

            model.SearchString = searchString;
            model.Gender       = gender;
            model.Sorting      = sorting;
            model.CurrentPage  = crruentPage;
            model.PageCount    = pageCount;
            var query = _messageRepository.GetAllMessagesToQuery();

            //查询
            if (!string.IsNullOrEmpty(searchString))
            {
                string crruentString = searchString.Trim();
                query = query.Where(s => s.Title.Contains(searchString));
            }
            //过滤
            if (gender != null)
            {
                List <Message> result = new List <Message>();
                foreach (var item in query)
                {
                    ApplicationUser user = await _userManager.FindByIdAsync(item.ApplicationUserId);

                    if (user.Gender == gender)
                    {
                        result.Add(item);
                    }
                }
                query = result.AsQueryable();
            }
            //排序
            switch (sorting)
            {
            case "Date":
                query = query.OrderBy(s => s.PublishTime);
                break;

            case "Date_Desc":
                query = query.OrderByDescending(s => s.PublishTime);
                break;

            case "Id":
                query = query.OrderBy(s => s.Id);
                break;

            default:
                query = query.OrderByDescending(s => s.Id);
                break;
            }
            //分页
            query = query.Skip((model.CurrentPage - 1) * pageCount)
                    .Take(pageCount);
            model.Messages = query.AsNoTracking().ToList();
            return(View(model));
        }
        public ViewResult Index()
        {
            var user            = SessionHelper.CurrentEntity;
            var mailboxMessages = messageRepository.MailboxMessages.Where(mb => mb.Viewers_EntityID == user.EntityID);



            var vm = new MessageIndexViewModel(mailboxMessages);

            return(View(vm));
        }
        // GET: Message
        public async Task <IActionResult> Index()
        {
            MessageIndexViewModel model = new MessageIndexViewModel();
            var user = await GetCurrentUserAsync();

            model.ReceivedMessages = await _context.Message
                                     .Where(cu => cu.ReceivingUser == user)
                                     .ToListAsync();

            model.SentMessages = await _context.Message
                                 .Where(cu => cu.SendingUser == user)
                                 .ToListAsync();

            return(View(model));
        }
示例#6
0
        public ActionResult Index(string id)
        {
            if (id == null)
            {
                return(this.RedirectToAction("Index", "Home"));
            }

            var user                = this.userService.GetByIndentityId(id);
            var userFriends         = this.friendService.GetAllUserFriends(user.Id);
            var mappedFriends       = this.viewModelService.GetMappedUserFriends(userFriends).ToList();
            var conversations       = this.conversationService.GetAllByUserId(id);
            var mappedConversations = this.viewModelService.GetMappedConversations(conversations);
            var model               = new MessageIndexViewModel();

            model.Friends       = mappedFriends;
            model.Conversations = mappedConversations;

            return(this.View(model));
        }
示例#7
0
        // GET: Messages
        public async Task<IActionResult> Index()
        {

            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var neighbor = _context.Neighbors.Where(n => n.ApplicationUserId == userId).FirstOrDefault();
            var url = $"https://maps.googleapis.com/maps/api/js?key={APIKey.SecretKey}&callback=initMap";
            var hashtags = _context.Hashtags.Where(h => h.NeighborId == neighbor.Id).Select(h => h.Text);
            MessageIndexViewModel messageIndexViewModel = new MessageIndexViewModel();
            var shopOwnersSubscribedTo = new List<ShopOwner>();
            var subscriptions = await _context.Subscriptions.Where(s => s.NeighborId == neighbor.Id).ToListAsync();
            var messageIds = new List<int?>();
            var messagesToPost = new List<Message>();
            var nonlocalMessagesToPost = new List<Message>();
            var messageHashtags = new List<MessageHashtag>();
            var messagesToUse = new List<Message>();
            var messagesOutsideZipCode = new List<Message>();
            var updatesOutsideZipCode = new List<Update>();


            messageHashtags = _context.MessageHashtags.ToList();

            //List<MessageIndexViewModel> messageIndexViewModels = new List<MessageIndexViewModel>();

            var messagesInZipCode = _context.Messages.Where(m => m.ZipCode == neighbor.ZipCode);//|| m => m.Zipcode == neighbor.OtherZipCodes)


            //check if hashtags match yours
            //then post

            foreach (var m in messagesInZipCode)
            {
                //MessageIndexViewModel messageIndexViewModelForMessage = new MessageIndexViewModel();
                //messageIndexViewModelForMessage.Message = m;
                //messageIndexViewModelForMessage.Message.Hashtags = m.Hashtags;
                var hashtagsInMessage = _context.MessageHashtags.Where(mH => mH.MessageId == m.Id).Select(mH => mH.Text);
                foreach (var h in hashtags)
                {
                    if (hashtagsInMessage.Contains(h))
                    {
                        if (messagesToPost.Contains(m))
                        {
                            continue;
                        }
                        else
                        {
                            messagesToPost.Add(m);
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

            }

            var outsideZipCodes = _context.ZipCodes.Where(z => z.NeighborId == neighbor.Id).ToList();

            foreach (var o in outsideZipCodes)
            {
                var messagesPerZipCode = _context.Messages.Where(m => m.ZipCode == o.NonLocalZipCode).ToList();
                foreach(var m in messagesPerZipCode)
                {
                    messagesOutsideZipCode.Add(m);
                }
                var updatesPerZipCode = _context.Updates.Where(u => u.ShopOwnerZipCode == o.NonLocalZipCode).ToList();
                foreach(var u in updatesPerZipCode)
                {
                    updatesOutsideZipCode.Add(u);
                }

            }

            foreach (var m in messagesOutsideZipCode)
            {
                var hashtagsInMessage = _context.MessageHashtags.Where(mH => mH.MessageId == m.Id).Select(mH => mH.Text).ToList();
                foreach (var h in hashtags)
                {
                    if (hashtagsInMessage.Contains(h))
                    {
                        if (nonlocalMessagesToPost.Contains(m))
                        {
                            continue;
                        }
                        else
                        {
                            nonlocalMessagesToPost.Add(m);
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            var nonlocalUpdatesToValidate = new List<Update>();
            foreach(var u in updatesOutsideZipCode)
            {
                foreach(var s in subscriptions)
                {
                    if (u.ShopOwnerId == s.ShopOwnerId && u.ZipCode == neighbor.ZipCode)
                    {
                        nonlocalUpdatesToValidate.Add(u);
                    }
                }
            }
            var nonlocalUpdatesToPost = ValidityCheck(nonlocalUpdatesToValidate);
            //    foreach (var mH in messageHashtags)
            //    {

            //        //if (m.Id == mH.MessageId)
            //        //{
            //        //    messagesToUse.Add(m);
            //        //}
            //    }

            //    messageHashtags = _context.MessageHashtags.Where(mH => mH.MessageId == m.Id).ToList();
            //}

            //foreach (var h in hashtags)
            //{
            //    foreach (var m in messageHashtags)
            //    {
            //        if (h.Text == m.Text)
            //        {
            //            //if (messageIds.Contains(m.Id))
            //            //{
            //            //    continue;
            //            //}
            //            //else
            //            //{
            //                messageIds.Add(m.MessageId);
            //            //}
            //        } 
            //    }
            //}
            //foreach (var messageId in messageIds)
            //{
            //    var message = _context.Messages.Where(m => m.Id == messageId).FirstOrDefault();
            //    messagesToPost.Add(message);

            //}

            var updates = _context.Updates.Where(u => u.ShopOwnerZipCode == neighbor.ZipCode).ToList();
            var updatesToValidate = new List<Update>();
            foreach (var u in updates)
            {
                foreach (var s in subscriptions)
                {
                    if (u.ShopOwnerId == s.ShopOwnerId)
                    {
                        updatesToValidate.Add(u);
                    }
                }
            }
            var updatesToPost = ValidityCheck(updatesToValidate);
            var shopOwners = _context.ShopOwners.ToList();
            foreach (var s in subscriptions)
            {
                foreach (var sO in shopOwners)
                {
                    if (s.ShopOwnerId == sO.Id)
                    {
                        shopOwnersSubscribedTo.Add(sO);
                    }
                }
            }
            var jArray = JArray.FromObject(shopOwnersSubscribedTo);
            var latLngs = new List<Dictionary<string, double>>();

            foreach (var s in shopOwnersSubscribedTo)
            {
                var locationDictionary = new Dictionary<string,double>();
                locationDictionary.Add("lat", s.Latitude);
                locationDictionary.Add("lng", s.Longitude);
                latLngs.Add(locationDictionary);
            }
            var locationsArray = latLngs.ToArray();
            messageIndexViewModel.Neighbor = neighbor;
            messageIndexViewModel.Messages = messagesToPost.OrderByDescending(m => m.DateTime).ToList();
            messageIndexViewModel.Updates = updatesToPost.OrderByDescending(m => m.StartDate).ToList();
            messageIndexViewModel.ShopOwners = shopOwnersSubscribedTo;
            messageIndexViewModel.LatLngs = locationsArray;
            messageIndexViewModel.ShopOwnersArray = jArray;
            messageIndexViewModel.Url = url;
            messageIndexViewModel.ZipCodes = outsideZipCodes;
            messageIndexViewModel.MessagesOutsideZipCode = nonlocalMessagesToPost.OrderByDescending(m => m.DateTime).ToList();
            messageIndexViewModel.UpdatesOutsideZipCode = nonlocalUpdatesToPost.OrderByDescending(u => u.StartDate).ToList();
            //messageIndexViewModel.Location = neighborLocation;
            return View(messageIndexViewModel);
        }