コード例 #1
0
        public async Task <IActionResult> Create(SPTareaCreateCLS Modelo)
        {
            if (Modelo is null)
            {
                throw new ArgumentNullException(paramName: nameof(Modelo));
            }

            using (HttpClient HttpClient = new HttpClient())
            {
                using (HttpContent ContentModel = new StringContent(JsonConvert.SerializeObject(Modelo), Encoding.UTF8, "application/json"))
                {
                    Uri URL = new UriBuilder(EndPoint + "api/Crud").Uri;
                    using (HttpResponseMessage RespuestaAPI = await HttpClient.PostAsync(URL, ContentModel).ConfigureAwait(true))
                    {
                        if (RespuestaAPI.IsSuccessStatusCode)
                        {
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            return(View());
                        }
                    }
                }
            }
        }
コード例 #2
0
        public async Task <int> Post([FromBody] SPTareaCreateCLS value)
        {
            HttpResponseMessage MensajeRespuesta;

            try
            {
                if (value is null)
                {
                    return(StatusCodes.Status400BadRequest);
                }
                else
                {
                    int TareaGuardar = await _repository.Insert(value);

                    if (TareaGuardar >= 1)
                    {
                        return(StatusCodes.Status201Created);
                    }
                    else
                    {
                        return(StatusCodes.Status500InternalServerError);
                    }
                }
            }
            catch (InvalidCastException e)
            {
                throw new Exception("Error: Error en listar " + e);
            }
        }
コード例 #3
0
        public async Task <int> Insert(SPTareaCreateCLS value)
        {
            using (SqlConnection sql = new SqlConnection(_connectionString)) {
                using (SqlCommand cmd = new SqlCommand("PA_CREATE_TAREA", sql)) {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@TAREAS_DESCRIPCION", value.TAREAS_DESCRIPCION));
                    cmd.Parameters.Add(new SqlParameter("@TAREAS_ESTADO", value.TAREAS_ESTADO));
                    cmd.Parameters.Add(new SqlParameter("@TAREAS_PRIORIDAD", value.TAREAS_PRIORIDAD));
                    cmd.Parameters.Add(new SqlParameter("@TAREAS_FECHA_INICIO", value.TAREAS_FECHA_INICIO));
                    cmd.Parameters.Add(new SqlParameter("@TAREA_FECHA_FIN", value.TAREA_FECHA_FIN));
                    cmd.Parameters.Add(new SqlParameter("@TAREAS_NOTAS", value.TAREAS_NOTAS));
                    cmd.Parameters.Add(new SqlParameter("@TAREAS_COLABORADOR", value.TAREAS_COLABORADOR));
                    await sql.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();

                    var exito = 1;
                    return(exito);
                }
            }
        }