コード例 #1
0
        public async Task <IActionResult> Crear(int id, ContactoVistaModelo contactoVistaModelo)
        {
            var receptorId = _dbBase.Receptores.Where(x => x.IdReceptor == id).Select(x => x.IdReceptor).FirstOrDefault();

            contactoVistaModelo.Contacto.ReceptorId = receptorId;
            if (ModelState.IsValid)
            {
                _dbBase.Add(contactoVistaModelo.Contacto);
                await _dbBase.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = receptorId }));
            }
            ContactoVistaModelo modelo = new ContactoVistaModelo()
            {
                Contacto   = new Contacto(),
                Receptores = new Receptores()
            };

            return(View(modelo));
        }