コード例 #1
0
        //[TestCase(100, false)]
        //[TestCase(1, false)]
        //[TestCase(100, true)]
        public void CanGetTagByReviewId(int id, bool success)
        {
            TResponse <List <Tags> > response = manager.GetTagByReviewId(id);

            Assert.AreEqual(response.Success, success);
            //Assert.AreEqual(response.Success, success); //index out of range/does not exists
            //Assert.AreNotSame(response.Success, success); //should not return false
            //Assert.AreNotSame(response.Success, success); //should not return true
        }
コード例 #2
0
        public ActionResult EditReview(ReviewVM model)
        {
            _tagsManager     = TagsManagerFactory.Create();
            _reviewManager   = ReviewManagerFactory.Create();
            _categoryManager = CategoryManagerFactory.Create();

            if (ModelState.IsValid)
            {
                try
                {
                    //set dates
                    model.Review.DateCreated = DateTime.Now;

                    //send review to manager
                    _reviewManager.EditReview(model.Review);

                    if (model.NewTags != null)
                    {
                        //create array of tags from tags input
                        string[] tags = model.NewTags.Split(',');

                        //send tags to tag manager
                        TResponse <List <Tags> > tagList = _tagsManager.AddListOfTags(tags);

                        //add tags to review
                        _reviewManager.AddTagsToReview(model.Review.ReviewId, tagList.Payload);
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    //catch an exception and add

                    throw new ApplicationException("Something wrong happened while adding a review:", ex);
                }
            }
            else
            {
                //reset view
                var tagsResponse = _tagsManager.GetTagByReviewId(model.Review.ReviewId);
                model.TagList = tagsResponse.Payload;
                TResponse <List <Categories> > response = _categoryManager.GetCategoryList();
                model.SetCategoryListItems(response.Payload);
                return(View(model));
            }
        }
コード例 #3
0
        public ActionResult EditReview(int id)
        {
            var model = new ReviewVM();

            //Get review by Id then pass the dude into a VM
            _reviewManager   = ReviewManagerFactory.Create();
            _categoryManager = CategoryManagerFactory.Create();
            _tagsManager     = TagsManagerFactory.Create();


            var reviewResponse = _reviewManager.GetReviewById(id);

            var tagResponse = _tagsManager.GetTagByReviewId(id);

            var categoryListResponse = _categoryManager.GetCategoryList();

            var categoryForReview = _categoryManager.GetCategoryByReviewId(id);

            if (reviewResponse.Success == true &&
                tagResponse.Success == true &&
                categoryListResponse.Success == true &&
                categoryForReview.Success == true)
            {
                model.Review = reviewResponse.Payload;

                model.TagList = tagResponse.Payload;

                model.SetCategoryListItems(categoryListResponse.Payload);

                model.Category = categoryForReview.Payload;

                return(View(model));

                //TResponse<List<Categories>> categoryListResponse = _categoryManager.GetCategoryList();

                //TResponse<Categories> categoryResponse = _categoryManager.GetCategoryByReviewId(id);
            }
            else
            {
                return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" +
                                                $"{reviewResponse.Message}" +
                                                $"{tagResponse.Message}" +
                                                $"{categoryListResponse.Message}" +
                                                $"{categoryForReview.Message}"));
            }
        }
コード例 #4
0
        public ActionResult EditReview(ReviewVM model)
        {
            _tagsManager     = TagsManagerFactory.Create();
            _reviewManager   = ReviewManagerFactory.Create();
            _categoryManager = CategoryManagerFactory.Create();

            if (ModelState.IsValid)
            {
                try
                {
                    //set dates
                    model.Review.DateCreated = DateTime.Now;

                    //send review to manager
                    _reviewManager.EditReview(model.Review);

                    if (model.NewTags != null)
                    {
                        //create array of tags from tags input
                        string[] tags = model.NewTags.Split(',');

                        //send tags to tag manager
                        var newlyAddedTagsResponse = _tagsManager.AddListOfTags(tags);

                        //get current tags
                        var currentTagsForReviewResponse = _tagsManager.GetTagsByReviewId(model.Review.ReviewId);

                        //add tags to review
                        _tagsManager.EditTagsForReview(model.Review.ReviewId,
                                                       newlyAddedTagsResponse.Payload,
                                                       currentTagsForReviewResponse.Payload);

                        return(RedirectToAction("Reviews"));
                    }
                    else
                    {
                        var response = _tagsManager.DeleteAllTagsForReview(model.Review.ReviewId);

                        if (!response.Success)
                        {
                            return(new HttpStatusCodeResult(500, $"Error in cloud. Message: {response.Message}"));
                        }

                        return(RedirectToAction("Reviews"));
                    }
                }
                catch (Exception ex)
                {
                    //catch an exception and add

                    throw new ApplicationException("Something wrong happened while adding a review:", ex);
                }
            }
            else
            {
                //reset view
                var tagsResponse = _tagsManager.GetTagByReviewId(model.Review.ReviewId);
                model.TagList = tagsResponse.Payload;
                TResponse <List <Categories> > response = _categoryManager.GetCategoryList();
                model.SetCategoryListItems(response.Payload);

                return(View(model));
            }
        }