public ActionResult Create(EmprestimoVM emprestimoVM)
        {
            try
            {
                string validarId = "00000000-0000-0000-0000-000000000000";
                if (emprestimoVM.Amigo.Id.ToString().Equals(validarId) ||
                    emprestimoVM.Jogo.Id.ToString().Equals(validarId))
                {
                    if (!ModelState.IsValid)
                    {
                        PreencherCombo();
                        return(View(emprestimoVM));
                    }
                }

                _business.Salvar(Mapper.Map <Emprestimo>(emprestimoVM));
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                PreencherCombo();
                ModelState.AddModelError("", e.Message);
                return(View(emprestimoVM));
            }
        }
Esempio n. 2
0
        public object PostSalvarEmprestimo(Emprestimo emprestimo)
        {
            if (emprestimo != null)
            {
                emprestimo.Usuario = User.Identity.Name;

                try
                {
                    _emprestimoBusiness.Salvar(emprestimo);
                    return(Json(new { operacaoConcluidaComSucesso = true }));
                }
                catch (ProjetoException pe)
                {
                    return(Json(new { operacaoConcluidaComSucesso = false, mensagem = pe.Message }));
                }
            }
            return(Json(new { operacaoConcluidaComSucesso = false }));
        }