Exemple #1
0
        public IActionResult Edit([Bind] RiddleViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var riddle = repository.GetRiddle(model.Id);
                    if (riddle == null)
                    {
                        return(NotFound());
                    }

                    logger.LogError($"Update riddle {model.Id}");
                    riddle.Question   = model.Question;
                    riddle.Answer     = model.Answer;
                    riddle.Difficulty = model.Difficulty;
                    riddle.Rank       = model.Rank;

                    repository.SaveAll();
                    return(RedirectToAction("Index"));
                }

                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                logger.LogError($"Failed to create riddle. {e}");
            }
            return(BadRequest("Failed to create riddle"));
        }
Exemple #2
0
        private RiddleViewModel GetRiddleOfTodayRiddleViewModel()
        {
            var             riddle     = repository.GetRiddleOfToday();
            RiddleViewModel riddleView = null;

            if (riddle != null)
            {
                riddleView = mapper.Map <Riddle, RiddleViewModel>(riddle);
            }
            return(riddleView);
        }
Exemple #3
0
 public IActionResult Create([Bind] RiddleViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var newRiddle = mapper.Map <RiddleViewModel, Riddle>(model);
             //var currentUser = await userManager.FindByNameAsync(User.Identity.Name);
             repository.AddEntity(newRiddle);
             repository.SaveAll();
             return(RedirectToAction("Index"));
         }
         return(BadRequest(ModelState));
     }
     catch (Exception e)
     {
         logger.LogError($"Failed to create riddle. {e}");
     }
     return(BadRequest("Failed to create riddle"));
 }