Example #1
0
        public ActionResult FeedsIndex()
        {
            // var vm = new  ChannelSelectionViewModel();
            var coll = new List <FeedSelectionViewModel>();
            // assemble a list of vms

            // all channels.
            var list = db.Channels;

            //index list of those channels currently subscribed by current user.
            var subsChannels = db.Channels.Where(ch => ch.UserProfile.ID == profile.ID);

            int[] ids = subsChannels.Select(x => x.FeedChannelID).ToArray();

            foreach (var feedItem in list)
            {
                //ids contains result is ID?
                bool contained = ids.Contains(feedItem.FeedChannelID);

                var newVm = new FeedSelectionViewModel( )
                {
                    FeedID = feedItem.FeedChannelID, FeedName = feedItem.FeedChannelName, FeedSelected = contained
                };
                coll.Add(newVm);
            }
            //  vm.AvailableChannels= coll;
            return(View(coll));
        }
Example #2
0
        public ActionResult EditDetails(FeedSelectionViewModel vm)
        {
            if (vm == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ;
            //if user tickled add to feed radio button , add this to the list of feeds current user is following.
            try
            {
                var         id  = vm.FeedID;
                FeedChannel chn = (FeedChannel)db.Channels.First(ch => ch.FeedChannelID == id);
                profile.SelectedChannels.Add(chn);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, $@"Unable to save the record. {ex.Message}");
                return(View(vm));
            }



            return(RedirectToAction("FeedsIndex"));
        }
Example #3
0
 // GET: NewsHome/Details/5
 public ActionResult Details(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     else
     {
         // instantiate vm
         var cnl = (FeedChannel)db.Channels.First(ch => ch.FeedChannelID == id);
         //   var newVm = new FeedSelectionViewModel( ) { FeedID = feedItem.FeedChannelID , FeedName = feedItem.FeedChannelName , FeedSelected = contained   };
         var newVm = new FeedSelectionViewModel()
         {
             FeedID = cnl.FeedChannelID, FeedName = cnl.FeedChannelName
         };
         return(View(newVm));
     }
 }