Ejemplo n.º 1
0
        public async Task <IActionResult> GetById(int?id)
        {
            LlamadaViewModel llamadaViewModel = new LlamadaViewModel();

            try
            {
                if (id == null)
                {
                    return(StatusCode(400, "Identificador nullo."));
                }
                List <LlamadaEntity> llamadaEntity = await _context.Llamadas.Where(x => x.Id.Equals(id)).ToListAsync();

                if (llamadaEntity == null || llamadaEntity.Count() == 0)
                {
                    return(StatusCode(404, "No se encontro la llamada"));
                }
                List <LlamadaViewModel> llamadaViewModels = llamadaEntity.ConvertAll(x => new LlamadaViewModel(x));
                llamadaViewModel = llamadaViewModels.FirstOrDefault();
                return(StatusCode(200, llamadaViewModel));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
            finally{
                llamadaViewModel = null;
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Update(LlamadaViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(400, "Modelo no válido."));
                }
                LlamadaEntity llamadaEntity = await _context.Llamadas.FindAsync(model.Id);

                if (llamadaEntity == null)
                {
                    return(StatusCode(404, "Llamada no existe."));
                }
                llamadaEntity.Mensaje             = model.Mensaje == null || model.Mensaje == "" ? llamadaEntity.Mensaje : model.Mensaje;
                llamadaEntity.TipoLlamadaEntityId = model.TipoLlamadaEntityId == 0 ? llamadaEntity.TipoLlamadaEntityId : model.TipoLlamadaEntityId;
                llamadaEntity.TipoPersonaEntityId = model.TipoPersonaEntityId == 0 ? llamadaEntity.TipoPersonaEntityId : model.TipoPersonaEntityId;
                _context.Llamadas.Update(llamadaEntity);
                await _context.SaveChangesAsync();

                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(LlamadaViewModel model)
        {
            LlamadaEntity llamadaEntity = new LlamadaEntity();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(400, "Modelo no válido."));
                }
                llamadaEntity.Mensaje             = model.Mensaje;
                llamadaEntity.TipoLlamadaEntityId = model.TipoLlamadaEntityId;
                llamadaEntity.TipoPersonaEntityId = model.TipoPersonaEntityId;
                await _context.Llamadas.AddAsync(llamadaEntity);

                await _context.SaveChangesAsync();

                return(RedirectToAction("GetById", "Llamadas", new { id = llamadaEntity.Id }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }finally
            {
                llamadaEntity = null;
            }
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> Update([FromBody] LlamadaViewModel model)
 {
     return(await _services.Update(model));
 }