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")); }
private RiddleViewModel GetRiddleOfTodayRiddleViewModel() { var riddle = repository.GetRiddleOfToday(); RiddleViewModel riddleView = null; if (riddle != null) { riddleView = mapper.Map <Riddle, RiddleViewModel>(riddle); } return(riddleView); }
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")); }