示例#1
0
        public async Task <ActionResult <Respuesta> > PostInstitucionTels([FromBody] InstitucionTelsRequest institucionTelsRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Respuesta
                {
                    EsExitoso = false,
                    Mensaje = "Modelo incorrecto.",
                    Resultado = ModelState
                }));
            }

            var user = await this.context.Users.FindAsync("1");

            if (user == null)
            {
                return(BadRequest(new Respuesta
                {
                    EsExitoso = false,
                    Mensaje = "Usuario Invalido.",
                    Resultado = null
                }));
            }

            var instituciones = await this.context.Instituciones.FindAsync(institucionTelsRequest.InstitucionId);

            if (instituciones == null)
            {
                return(BadRequest(new Respuesta
                {
                    EsExitoso = false,
                    Mensaje = "Institucion no existe.",
                    Resultado = null
                }));
            }

            var entity = new InstitucionTels
            {
                InstitucionId = institucionTelsRequest.InstitucionId,
                TelId         = institucionTelsRequest.TelId,
                Usuario       = user,
            };

            BaseController.CompletaRegistro(entity, 1, "", user, false);

            await this.context.Set <InstitucionTels>().AddAsync(entity);

            try
            {
                await this.context.SaveChangesAsync();
            }
            catch (Exception ee)
            {
                return(BadRequest(new Respuesta
                {
                    EsExitoso = false,
                    Mensaje = "Registro no grabado, controlar.",
                    Resultado = null
                }));
            }

            //return Ok(new Respuesta
            //{
            //    EsExitoso = true,
            //    Mensaje = "",
            //    Resultado = entity
            //});

            return(Ok(new Respuesta
            {
                EsExitoso = true,
                Mensaje = "",
                Resultado = new InstitucionTelsRespuesta
                {
                    InstitucionId = entity.InstitucionId,
                    TelId = entity.TelId,
                }
            }));
        }
示例#2
0
        public async Task <ActionResult <InstitucionTels> > PutInstitucionTels(int id, [FromBody] InstitucionTelsRequest institucionTelsRequest)
        {
            var entity = await this.context.Set <InstitucionTels>().FindAsync(id);

            var instituciones = await this.context.Instituciones.FindAsync(institucionTelsRequest.InstitucionId);

            if (instituciones == null)
            {
                return(BadRequest(new Respuesta
                {
                    EsExitoso = false,
                    Mensaje = "Institicion no existe.",
                    Resultado = null
                }));
            }
            entity.InstitucionId             = institucionTelsRequest.InstitucionId;
            entity.TelId                     = institucionTelsRequest.TelId;
            this.context.Entry(entity).State = EntityState.Modified;
            await this.context.SaveChangesAsync();

            return(Ok(new Respuesta
            {
                EsExitoso = true,
                Mensaje = "",
                Resultado = new InstitucionTelsRespuesta
                {
                    InstitucionId = entity.InstitucionId,
                    TelId = entity.TelId,
                }
            }));
        }