コード例 #1
0
        public JsonResult RemovePeer(RemovePeerViewModel viewModel, int id)
        {
            if (id != viewModel.ReviewId) {
                throw new ArgumentException("id");
            }

            var response = new JsonResultDataModel();
            var reviewConfiguration = _db.ReviewConfigurations.Find(viewModel.ReviewId);
            if (reviewConfiguration == null) {
                return new JsonResult { Data = response.Status("error").Message("The requested review could not be found!") };
            }
            var peer = reviewConfiguration.Peers.SingleOrDefault(user => user.EmailAddress == viewModel.PeerEmail);
            if (peer == null) {
                return new JsonResult { Data = response.Status("error").Message("The desired peer could not be found") };
            }
            var success = reviewConfiguration.Peers.Remove(peer);
            _db.SaveChanges();

            return new JsonResult
                       {
                           Data = response
                               .Status(success ? "success" : "error")
                               .Message(success ? "The peer was successfully removed." : "An error occurred while removing the peer!")
                       };
        }
コード例 #2
0
        public JsonResult RemoveCategory(RemoveCategoryViewModel viewModel, int id)
        {
            if (id != viewModel.ReviewId) {
                throw new ArgumentException("id");
            }

            var response = new JsonResultDataModel();
            var reviewConfiguration = _db.ReviewConfigurations.Find(viewModel.ReviewId);
            if (reviewConfiguration == null) {
                return new JsonResult { Data = response.Status("error").Message("The requested review could not be found!") };
            }
            var category = reviewConfiguration.Categories.SingleOrDefault(cat => cat.Id == viewModel.CategoryId);
            if (category == null) {
                return new JsonResult { Data = response.Status("error").Message("The desired category could not be found") };
            }
            var success = reviewConfiguration.Categories.Remove(category);
            _db.SaveChanges();

            return new JsonResult
                       {
                           Data = response
                               .Status(success ? "success" : "error")
                               .Message(success
                                            ? "The category was successfully removed."
                                            : "An error occurred while removing the category!")
                       };
        }