public ActionResult Create(UserModel model) { try { if (ModelState.IsValid) { try { if (_userService.Get(w => w.Email.Equals(model.Email)) != null) { ShowMessageDialog(MensagensResource.EmailExistente, Message.MessageKind.Warning); model.ProfileDictionary = _ProfileService.GetDictionary(); model.HierarchyDictionary = _hierarchyService.GetDictionary(); return(View(model)); } model.Senha = _userService.GetCodigoRecover(); model.CodigoRecover = _userService.GetCodigoRecover(); var entity = Mapper.Map <UserModel, User>(model); _userService.Add(entity, CurrentUser.UserId); var email = new EmailMail { From = ConfigurationManager.AppSettings["EmailFrom"], To = new List <string> { model.Email }, Subject = "New User", Body = "You are a new user of the system..." }; _emailMailService.SendEmail(email); } catch (Exception e) { ShowMessageDialog(MensagensResource.SucessoCadastrarErroEmail, e); return(RedirectToAction("Index")); } ShowMessageDialog(MensagensResource.SucessoCadastrarSucessoEmail, Message.MessageKind.Success); } else { model.ProfileDictionary = _ProfileService.GetDictionary(); model.HierarchyDictionary = _hierarchyService.GetDictionary(); return(View(model)); } } catch (Exception e) { ShowMessageDialog(MensagensResource.ErroCadastrar, e); } return(RedirectToAction("Index")); }