Exemplo n.º 1
0
        public async Task <string> SavePepperAsync(PepperModel model)
        {
            SqlCommand insert = new SqlCommand("insert into Peppers values(@id, @name);", conn);

            insert.Parameters.AddWithValue("@id", model.ID);
            insert.Parameters.AddWithValue("@name", model.Name);

            conn.Open();

            try
            {
                SqlDataAdapter dataAdapter = new SqlDataAdapter();
                dataAdapter.InsertCommand = insert;
                await dataAdapter.InsertCommand.ExecuteNonQueryAsync();

                conn.Close();

                return("Ok");
            }
            catch (Exception e)
            {
                conn.Close();
                return(e.ToString());
            }
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> UpdatePepperAsync(PepperModel model)
        {
            int response = await _service.UpdatePepperAsync(model);

            if (response == 200)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Successfully updated database."));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Unsuccessful!"));
            }
        }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> SavePepperAsync(PepperModel model)
        {
            string response = await _service.SavePepperAsync(model);

            if (response == "Ok")
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Successfully updated database."));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, response));
            }
        }
Exemplo n.º 4
0
        public async Task <int> UpdatePepperAsync(PepperModel model)
        {
            SqlCommand update = new SqlCommand("update Peppers set PepperName = @name where PepperID = @id;", conn);;

            update.Parameters.AddWithValue("@id", model.ID);
            update.Parameters.AddWithValue("@name", model.Name);

            conn.Open();

            try
            {
                await update.ExecuteNonQueryAsync();

                conn.Close();
                return(200);
            }
            catch (Exception)
            {
                conn.Close();
                return(400);
            }
        }
Exemplo n.º 5
0
        public async Task <List <PepperModel> > GetAllPeppersAsync()
        {
            SqlCommand         show    = new SqlCommand("select * from Peppers;", conn);
            List <PepperModel> peppers = new List <PepperModel>();

            conn.Open();
            SqlDataReader reader = await show.ExecuteReaderAsync();

            try
            {
                string name = "";
                int    id;
                if (reader.HasRows)
                {
                    while (await reader.ReadAsync())
                    {
                        id   = reader.GetInt32(0);
                        name = reader.GetString(1);

                        PepperModel pepper = new PepperModel();

                        pepper.ID   = id;
                        pepper.Name = name;

                        peppers.Add(pepper);
                    }
                }

                reader.Close();
                conn.Close();
                return(peppers);
            }
            catch (Exception)
            {
                conn.Close();
                return(null);
            }
        }
Exemplo n.º 6
0
 public async Task <int> UpdatePepperAsync(PepperModel model)
 {
     return(await Repository.UpdatePepperAsync(model));
 }
Exemplo n.º 7
0
 public async Task <string> SavePepperAsync(PepperModel model)
 {
     return(await Repository.SavePepperAsync(model));
 }