Exemplo n.º 1
0
        public ActionResult ReviewSubmission(int id, PostState review)
        {
            PostManager mgr = new PostManager();

            var response = mgr.GetById(id);

            if (response.Success)
            {
                response.Payload.PostState = review;

                var reviewResponse = mgr.EditPost(response.Payload);

                if (reviewResponse.Success)
                {
                    return(RedirectToAction("ViewSubmissions"));
                }
                else
                {
                    throw new Exception(reviewResponse.Message);
                }
            }
            else
            {
                throw new Exception(response.Message);
            }
        }
Exemplo n.º 2
0
        public async void EditPost_UpdatesExistingPost()
        {
            DbContextOptions <TwaddleDbContext> options = new DbContextOptionsBuilder <TwaddleDbContext>().UseInMemoryDatabase("EditPost").Options;

            using (TwaddleDbContext _context = new TwaddleDbContext(options))
            {
                //arrange
                Post one = new Post();
                one.Caption = "test";
                PostManager service = new PostManager(_context);
                await service.MakePost(one);

                //act
                one.Caption = "updated";
                await service.EditPost(one);

                //assert
                Assert.Equal("updated", (await service.GetOnePost(1)).Caption);
            }
        }
Exemplo n.º 3
0
        //[Authorize(Roles = "Marketing")]
        public ActionResult EditSubmission(SubmissionVM model)
        {
            if (ModelState.IsValid)
            {
                var postMgr = new PostManager();
                var catMgr  = new CategoryManager();
                var tagMgr  = new TagManager();

                var editTarget = postMgr.GetById(int.Parse(model.SubmissionId));
                //sub.Id = int.Parse(model.SubmissionId);
                editTarget.Payload.PostTitle         = model.SubmissionTitle;
                editTarget.Payload.PostBody          = model.SubmissionBody;
                editTarget.Payload.PostImageFileName = model.SubmissionImageFileName;

                var catResponse = catMgr.GetCategoryById(int.Parse(model.SubmissionCategoryId));

                if (catResponse.Success)
                {
                    editTarget.Payload.PostCategory = catResponse.Payload;
                }
                else
                {
                    throw new Exception(catResponse.Message);
                }

                var tagResponse = tagMgr.ConvertTagStringToList(model.SubmissionTags);

                if (tagResponse.Success)
                {
                    var tagList = new List <Tag>();

                    foreach (var t in tagResponse.Payload)
                    {
                        t.Posts.Add(editTarget.Payload);
                        tagMgr.AddTag(t);
                        tagList.Add(t);
                    }

                    editTarget.Payload.PostTags = tagList;
                }
                else
                {
                    throw new Exception();
                }

                editTarget.Payload.PostState = PostState.Pending;
                editTarget.Payload.Username  = User.Identity.Name;

                var subResponse = postMgr.EditPost(editTarget.Payload);

                if (subResponse.Success)
                {
                    return(RedirectToAction("ViewSubmissions"));
                }
                else
                {
                    throw new Exception(subResponse.Message);
                }
            }
            else
            {
                return(View(model));
            }
        }
Exemplo n.º 4
0
 public ActionResult EditPost(Post post)
 {
     _postManager.EditPost(post);
     return(View("EditPostSuccess", post));
 }