Example #1
0
        public async Task <IActionResult> Create(TipoPersonaViewModel model)
        {
            TipoPersonaEntity tipoPersonaEntity = new TipoPersonaEntity();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(404, "Modelo no válido"));
                }
                tipoPersonaEntity.Tipo          = model.Tipo;
                tipoPersonaEntity.FechaRegistro = DateTime.UtcNow;
                await _context.TipoPersona.AddAsync(tipoPersonaEntity);

                await _context.SaveChangesAsync();

                return(RedirectToAction("GetById", "TipoPersona", new { id = tipoPersonaEntity.Id }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
            finally
            {
                tipoPersonaEntity = null;
            }
        }
Example #2
0
        public async Task <IActionResult> Delete(int?id)
        {
            TipoPersonaEntity tipoPersonaEntity = new TipoPersonaEntity();

            try
            {
                if (id == null)
                {
                    return(StatusCode(400, "Identificador nulo"));
                }
                tipoPersonaEntity = await _context.TipoPersona.FindAsync(id);

                if (tipoPersonaEntity == null)
                {
                    return(StatusCode(404, "El tipo de persona no se encuentra"));
                }
                _context.TipoPersona.Remove(tipoPersonaEntity);
                await _context.SaveChangesAsync();

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Example #3
0
        public async Task <IActionResult> Update(TipoPersonaViewModel model)
        {
            TipoPersonaEntity tipoPersonaEntity = new TipoPersonaEntity();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(400, "Modelo no válido"));
                }
                tipoPersonaEntity = await _context.TipoPersona.FindAsync(model.Id);

                if (tipoPersonaEntity == null)
                {
                    return(StatusCode(404, "Tipo de persona no encontrada"));
                }
                tipoPersonaEntity.Tipo          = model.Tipo;
                tipoPersonaEntity.FechaRegistro = DateTime.UtcNow;
                _context.TipoPersona.Update(tipoPersonaEntity);
                await _context.SaveChangesAsync();

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
            finally
            {
                tipoPersonaEntity = null;
            }
        }
Example #4
0
 public TipoPersonaViewModel(TipoPersonaEntity x)
 {
     this.Id            = x.Id;
     this.Tipo          = x.Tipo;
     this.FechaRegistro = x.FechaRegistro;
 }