Exemplo n.º 1
0
        public void CanEnsureChannelCreationIsValid()
        {
            Channel ChannelFromForm = new Channel();
            ViewResult result = controller.Create(ChannelFromForm).AssertViewRendered();

            result.ViewData.Model.ShouldNotBeNull();
            result.ViewData.Model.ShouldBeOfType(typeof(ChannelsController.ChannelFormViewModel));
        }
Exemplo n.º 2
0
        public void CanCompareChannels()
        {
            Channel instance = new Channel();
            EntityIdSetter.SetIdOf<int>(instance, 1);

            Channel instanceToCompareTo = new Channel();
            EntityIdSetter.SetIdOf<int>(instanceToCompareTo, 1);

            instance.ShouldEqual(instanceToCompareTo);
        }
Exemplo n.º 3
0
        public ActionResult Create(Channel Channel)
        {
            Channel.owner = UserRepository.FindOne( new { Username = User.Identity.Name } );
            if (ViewData.ModelState.IsValid && Channel.IsValid()) {
                ChannelRepository.SaveOrUpdate(Channel);

                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                    "The Channel was successfully created.";
                return RedirectToAction("Index");
            }

            ChannelFormViewModel viewModel = ChannelFormViewModel.CreateChannelFormViewModel();
            viewModel.Channel = Channel;
            return View(viewModel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a valid, transient Channel; typical of something retrieved back from a form submission
        /// </summary>
        private Channel CreateTransientChannel()
        {
            Channel Channel = new Channel() {
                name = "TheChannel",
                owner = new User(),
            };

            return Channel;
        }
Exemplo n.º 5
0
 private void TransferFormValuesTo(Channel ChannelToUpdate, Channel ChannelFromForm)
 {
     ChannelToUpdate.name = ChannelFromForm.name;
 }
Exemplo n.º 6
0
 public IList<Post> GetPostsForChannel(Channel c, int Page)
 {
     SoulsController sc = new SoulsController(SoulRepository, PostRepository, null, null);
     List<Post> p = new List<Post>();
     foreach (var u in c.users)
     {
         p.AddRange(sc.GetPostsForSoul(u.Id, Page, 10));
     }
     return p.OrderBy(x => x.lastedit).Reverse().ToList();
 }
Exemplo n.º 7
0
        public ActionResult Edit(Channel Channel)
        {
            Channel ChannelToUpdate = ChannelRepository.Get(Channel.Id);
            TransferFormValuesTo(ChannelToUpdate, Channel);
            if (ChannelToUpdate.owner.Username != User.Identity.Name)
            {
                throw new HttpException(401, "HTTP/1.1 401 Unauthorized");
            }
            if (ViewData.ModelState.IsValid && Channel.IsValid()) {
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                    "The Channel was successfully updated.";
                return RedirectToAction("Index");
            }
            else {
                ChannelRepository.DbContext.RollbackTransaction();

                ChannelFormViewModel viewModel = ChannelFormViewModel.CreateChannelFormViewModel();
                viewModel.Channel = Channel;
                return View(viewModel);
            }
        }