コード例 #1
0
        public async Task <IActionResult> Update(TipoLLamadasViewModel model)
        {
            TipoLlamadaEntity tipoLlamadaEntity = new TipoLlamadaEntity();

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

                if (tipoLlamadaEntity == null)
                {
                    return(StatusCode(404, "Tipo de llamada no encontrada."));
                }
                tipoLlamadaEntity.Tipo          = model.Tipo == null || model.Tipo == "" ? tipoLlamadaEntity.Tipo : model.Tipo;
                tipoLlamadaEntity.FechaRegistro = DateTime.UtcNow;
                _context.Update(tipoLlamadaEntity);
                await _context.SaveChangesAsync();

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create(TipoLLamadasViewModel model)
        {
            TipoLlamadaEntity tipoLlamadaEntity = new TipoLlamadaEntity();

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

                await _context.SaveChangesAsync();

                return(RedirectToAction("GetById", "TipoLlamadas", new { id = tipoLlamadaEntity.Id }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
            finally
            {
                tipoLlamadaEntity = null;
            }
        }
コード例 #3
0
        public async Task <IActionResult> Delete(int?id)
        {
            try
            {
                if (id == null)
                {
                    return(StatusCode(400, "Identificador nulo."));
                }
                TipoLlamadaEntity tipoLlamadaEntity = await _context.TipoLlamadas.FindAsync(id);

                if (tipoLlamadaEntity == null)
                {
                    return(StatusCode(404, "Tipo de llamada no encontrada"));
                }
                _context.TipoLlamadas.Remove(tipoLlamadaEntity);
                await _context.SaveChangesAsync();

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
コード例 #4
0
 public TipoLLamadasViewModel(TipoLlamadaEntity x)
 {
     this.Id            = x.Id;
     this.Tipo          = x.Tipo;
     this.FechaRegistro = x.FechaRegistro;
 }