public void InsertPost(PostInsertVm postVm) { if (CheckDuplicateTitle(postVm)) { throw new BusinessRoleException("Já existe um post com esse título"); } this._repository.Insert(mapper.Map <Post>(postVm)); }
public bool CheckDuplicateTitle(PostInsertVm postVm) { var post = GetByTitle(postVm.Titulo); if (post != null) { return(true); } return(false); }
public IActionResult Insert(PostInsertVm postVm) { if (!ModelState.IsValid) { return(View()); } try { _postService.InsertPost(postVm); return(RedirectToAction("Index")); } catch (BusinessRoleException ex) { ModelState.AddModelError("", ex.Message); return(View()); } catch (Exception ex) { ViewData["Erro"] = ex.Message; return(View("_Erro")); } }