Пример #1
0
        public RecipeModelDto getRecipe(int rec_id)
        {
            MySqlCommand command = new MySqlCommand();

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }
            command.Connection  = connection;
            command.CommandText = "select c.id, c.name, c.description, c.type, c.steps, u.user_name from recipe c inner join user u on u.id=c.chef_id where c.id=" + rec_id;

            MySqlDataReader reader = command.ExecuteReader();
            RecipeModelDto  r      = new RecipeModelDto();

            if (reader.Read())
            {
                r.id          = reader.GetInt32("id");
                r.chef_name   = reader.GetString("user_name");
                r.description = reader.GetString("description");
                r.name        = reader.GetString("name");
                r.steps       = reader.GetString("steps");
                r.typeRec     = reader.GetString("type");
            }
            reader.Close();
            connection.Close();
            return(r);
        }
Пример #2
0
        public ActionResult <Boolean> updateRec(Int32 rec_id, RecipeModelDto rec)
        {
            string    tok = (string)Request.Headers["Authorization"];
            UserModel usr = userService.GetUserBySessionToken(tok);

            if (usr.id == 0)
            {
                return(BadRequest(false));
            }
            if (!userService.SessionIsValid(tok, DateTime.Now))
            {
                return(BadRequest(false));
            }
            userService.UpdateSessionTtl(usr.id, DateTime.Now.AddMinutes(30));
            return(Ok(service.UpdateRecipe(rec.id, usr.id, rec.description, rec.steps, rec.typeRec)));
        }