public ActionResult Create(EditFeedModel model)
 {
     if (!ModelState.IsValid)
     {
         return Redirect(Url.Feed_Create(model.ProjectId));
     }
     var obj = ModelConverter.Convert(model);
     obj.Id = FeedLogic.Create(obj, CurrentUserName);
     if (!obj.Id.HasValue || obj.Id < 0)
     {
         this.AddError("ErrorCreatingFeed", "There was an error creating your feed.");
         return Redirect(Url.Feed_Create(model.ProjectId));
     }
     return Redirect(Url.Feed_Show(obj.Id.Value));
 }
 internal static FeedObj Convert(EditFeedModel model)
 {
     return new FeedObj
     {
         Id = model.Id,
         Type = new FeedTypeObj { Id = (int)model.Type },
         Projects = new List<ProjectObj>
         {
             new ProjectObj
             {
                 Id = model.ProjectId
             }
         }
     };
 }
        public void Create_Post_Save_Success()
        {
            //arrange
            var mockLogic = new Mock<IFeedLogic>(MockBehavior.Strict);
            var newId = 3;
            mockLogic.Setup(m => m.Create(It.IsAny<FeedObj>(), It.IsAny<string>())).Returns(newId);
            var model = new EditFeedModel() { ProjectId = 2 };
            var controller = new FeedController(mockLogic.Object, null);
            controller = SetupController(controller);

            //act
            var actual = controller.Create(model) as RedirectResult;
            var expectedUrl = controller.Url.Feed_Show(newId);

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedUrl, actual.Url);
        }
        public void Create_Post_Bad_ModelState()
        {
            //arrange
            var mockLogic = new Mock<IFeedLogic>(MockBehavior.Strict);
            var projectId = 2;
            var model = new EditFeedModel() { ProjectId = projectId };
            var controller = new FeedController(mockLogic.Object, null);
            controller = SetupController(controller);
            controller.ModelState.AddModelError("test", "test");

            //act
            var actual = controller.Create(model) as RedirectResult;
            var expectedUrl = controller.Url.Feed_Create(projectId);

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedUrl, actual.Url);
        }
        public ActionResult Create(int projectId)
        {
            var projObj = ProjectLogic.Get(projectId);
            if (projObj == null)
            {
                this.AddError("ProjectNotFound", "That project could not be found");
                return Redirect(Url.Project_Index());
            }

            var model = new EditFeedModel
            {
                ProjectId = projectId
            };

            var types = FeedLogic.GetFeedTypes();
            model.AvailableTypes = types.ToList().Select(t => new SelectListItem() { Text = t.ToDescription(), Value = ((int)t).ToString() });

            return View("Edit", model);
        }