public IActionResult Jokes()
        {
            JokeRepository repo = new JokeRepository(_connectionString);
            JokesViewModel vm   = new JokesViewModel();

            vm.Jokes       = repo.GetAllJokes();
            vm.CurrentUser = repo.GetUserByEmail(User.Identity.Name);
            return(View(vm));
        }
        public ActionResult DeleteJoke(JokesViewModel jokeViewModel)
        {
            bool wasDeleted = _jokeService.Delete(Mapper.Map <IJoke>(jokeViewModel));

            if (wasDeleted)
            {
                return(Json(new
                {
                    status = "OK"
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                status = "ERROR",
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult UpdateJoke(JokesViewModel jokeViewModel)
        {
            IJoke jokeUpdated = _jokeService.Update(Mapper.Map <IJoke>(jokeViewModel));

            if (jokeUpdated != null)
            {
                return(Json(new
                {
                    status = "OK",
                    data = Mapper.Map <JokesViewModel>(jokeUpdated)
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                status = "ERROR",
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddJoke(JokesViewModel jokeViewModel)
        {
            IJoke jokeAddedModel = _jokeService.Add(Mapper.Map <IJoke>(jokeViewModel));

            if (jokeAddedModel != null)
            {
                return(Json(new
                {
                    status = "OK",
                    data = Mapper.Map <JokesViewModel>(jokeAddedModel)
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                status = "ERROR",
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #5
0
 public JokesPage()
 {
     InitializeComponent();
     DataContext = new JokesViewModel();
 }