Example #1
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Nombre,Chip,FechaNacimiento,CodRazaId,IdJaula")] Perros perros)
        {
            if (ModelState.IsValid)
            {
                repositorio.Insert(perros);
                await repositorio.Save();

                return(RedirectToAction("Index"));
            }

            ViewBag.IdJaula   = new SelectList(await repositorio.ListaJaulas(), "Id", "NombreJaula", perros.IdJaula);
            ViewBag.CodRazaId = new SelectList(await repositorio.ListaRazas(), "Id", "Nombre", perros.CodRazaId);
            return(View(perros));
        }
Example #2
0
        public async Task <ActionResult> Create([Bind(Include = "Nombre,Chip,FechaNacimiento,RazaId,JaulaId")] Perros perros)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _repository.Insert(perros).ConfigureAwait(false);
                }
                catch (DataException dex)
                {
                    throw new PerrosException("Error al crear un perro.", dex);
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.JaulaId = new SelectList(_repository.GetContext().Jaulas, "Id", "NombreJaula", perros.JaulaId);
            ViewBag.RazaId  = new SelectList(_repository.GetContext().Razas, "Id", "Nombre", perros.RazaId);
            return(View(perros));
        }