public async Task <IActionResult> Post([FromBody] asisChecada asisChecada)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Usuarios usua = await _context.Usuarios.FirstOrDefaultAsync(u => u.UsuTelefono == asisChecada.Celular);

            if (usua.UsuActivo)
            {
                if (!HayExcepciones(usua.UsuId))
                {
                    string res = AltaIncidencia(usua.UsuId, DateTime.Now, asisChecada.Guid);
                    var    rep = new Response <asisChecada> {
                        IsSuccess = true, Message = res, Result = null
                    };
                    if (res != "")
                    {
                        return(Ok(rep));
                    }
                    else
                    {
                        return(Ok("Hoy no checas"));
                    }
                }
            }
            else
            {
                return(Ok("Lo siento, pero estás suspendido."));
            }
            return(BadRequest("Error interno"));
        }
Exemple #2
0
        public async Task <Response <asisChecada> > PostChecadaAsync(string urlBase, string servicePrefix, string controller, string tokenType, string accessToken, asisChecada checada)
        {
            try
            {
                var requestString = JsonConvert.SerializeObject(checada);
                var content       = new StringContent(requestString, Encoding.UTF8, "application/json");
                var client        = new HttpClient {
                    BaseAddress = new Uri(urlBase)
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken);
                var url      = $"{servicePrefix}{controller}";
                var response = await client.PostAsync(url, content);

                var result = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return new Response <asisChecada> {
                               IsSuccess = false, Message = result, Result = null
                    }
                }
                ;

                var serializado = JsonConvert.DeserializeObject <Response <asisChecada> >(result);
                return(new Response <asisChecada>
                {
                    IsSuccess = serializado.IsSuccess,
                    Message = serializado.Message,
                    Result = serializado.Result
                });
            }
            catch (Exception ex)
            {
                return(new Response <asisChecada> {
                    IsSuccess = false, Message = ex.Message
                });
            }
        }